// Main.js  :   misc routines 
//  


//    Put the 'msg_alert' box on the page for possible use  __________________
var clearcount = new Array() ;  
clearcount = 0;

function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
	} 
	}


//<![CDATA[
function UNhideObj(ThisObj){
	nav=document.getElementById(ThisObj).style ;
	nav.display='block';
}

function HideandUNhideObj(ThisObj){
	nav=document.getElementById(ThisObj).style ;
		if(nav.display=="none"){
			nav.display='block';
		 }
		else{
				nav.display='none';
				}
}


function HideObj(ThisObj){
	nav=document.getElementById(ThisObj).style ;
	nav.display='none';
}

function Changeimage(ThisImg, whichfile) {
	var chngimg=document.getElementById(ThisImg) ;
	chngimg.src = whichfile;
}

function Changebgimage(ThisImg, whichfile) {
	var chngimg=document.getElementById(ThisImg) ;
	chngimg.background.image = whichfile;
}

//  End -->
//]]>


function writedatehiddeninputvalue()
{
	var d = new Date() ;
	var dateofquest =  d.toDateString() ;
	var timeofquest = d.toTimeString() ;
	var timeonly = timeofquest.substr(0,5);
	var datenoday = dateofquest.substr(4,11);
	var date_time = datenoday + ", "+ timeonly ;
//	var date_time = datenoday + ",&nbsp;"+ timeonly ;
	document.write("<input name='dateq' id='dateq' value='"+ date_time  + "' type='hidden' />" );
//	alert(date_time ) ; 

}  

function checkdropval(minnum, maxnum)
	{
		var priceform = document.forms[0];
		var choice = "0";
		var numberdesired = priceform.item_quantity_1.value ;
		if (numberdesired >= minnum && numberdesired <= maxnum )   {    return true; }
		switch (numberdesired)
		{
		case "0":     {   alert(" Choose a number from the drop down list.\n  A number must be specified \n To retry, click this 'OK' below to try again."); return false;  break;   }
		default:	    {     
				      alert(" Choose a number from the drop down list.\n  A number must be specified \n  To retry, click this 'OK' below to try again."); 
				      return false; break;   
				}
		 }
	}

function checksix_greater(minnum, maxnum)
	{
		var numberdesired = document.getElementById("item_quantity_1").value ;
		if (numberdesired >= minnum && numberdesired <= maxnum )   {    return true; }
		switch (numberdesired)
		{
		case "0":     {   alert("Type a number 6 or greater up to 99.\n A non-decimal number must be specified. \n To re-specify a number less than 6, use the back arrow to reset price range. \n For more than 99 DVD's, send me an email. \n To retry, click this 'OK' below to try again."); return false;  break;   }
		default:	    {     
				      alert("Type a number 6 or greater up to 99.\n A non-decimal number must be specified. \n To re-specify a number less than 6, use the back arrow to reset price range. \n For more than 99 DVD's, send me an email. \n To retry, click this 'OK' below to try again."); 
				      return false; break;   
				}
		 }
	}

function check_minmax(minnum, maxnum)
	{
		var numberdesired = document.getElementById("item_quantity_1").value ;
		if (numberdesired >= minnum && numberdesired <= maxnum )   {    return true; }
		switch (numberdesired)
		{
		case "0":     {   alert("Type a number 1 or greater up to 99.\n A non-decimal number must be specified. \n For more than 99 DVD's, send me an email. \n To retry, click this 'OK' below to try again."); return false;  break;   }
		default:	    {     
				      alert("Type a number 1 or greater up to 99.\n A non-decimal number must be specified. \n For more than 99 DVD's, send me an email. \n To retry, click this 'OK' below to try again."); 
				      return false; break;   
				}
		 }
	}
	
	
//	document.getElementById("question").innerHTML=question;
//	document.getElementById("answer").innerHTML=answer;
//	document.getElementById("email").innerHTML=email;
//	document.getElementById("screenname").innerHTML=screenname;
function check_field(msg, field_id)
	{
		var inptxt = document.getElementById(field_id).value.replace(/  /gm,' ') ;
		var spacesonly= false; if (document.getElementById(field_id).value.replace(/ /gm,'') == "") { spacesonly= true;};
		var sign=inptxt.indexOf('@') ;
		var emchk = true; if (field_id=='email') { emchk =  !(sign<1 || sign==(inptxt.length-1)) }; 
//		if (emchk==false) {alert("Email chk is " + emchk + "@sign test is " + sign)}  ;
		if (inptxt == "" || inptxt == msg || document.getElementById(field_id).value.substring(0,14)== "_please enter " || emchk==false )   
			{   
//				msg = msg + "\n input- " + inptxt ;
				alert(msg); 
				return false;     
			}
//		else { document.getElementById(field_id).value = inptxt;}
	}
	//"Need some input\n Must have a full name. \nOnly a screen name will be shown \n \n To retry, click this 'OK' below to try again."
	
function clearprompt(field_id) 
	{ 
		if (document.getElementById(field_id).value.substring(0,14)== "_please enter ") {document.getElementById(field_id).value = ""; } 
	}
	
function resetprompt(field_id)
	{
		if (document.getElementById(field_id).value.substring(0,14)== "") {document.getElementById(field_id).value = ""; } 
	}
	
function check_quest_form()
	{
		if (check_field('Please enter your name, non-blank. \nOnly a screen name will be shown on the Ask Andrea page. \n \n To retry, click OK.', 'fullname')==false)
			{ return false;}
		if  (check_field('Please enter a screen nick name, non-blank. \nThis  screen name will be shown on the webpage with your question. \n \n To retry, click OK.', 'screenname')==false)
			{ return false; }
		if ( check_field('Please enter a valid email address. E.g. id@webname.ext \nAndrea shall use this if she needs to contact you about your question. \n \n To retry, click OK.', 'email')==false )
			{ return false; }
	}

function msgbox()
{
/*	msg="Please Wait while Server is updated? ..."             */
/*	txt="<div id='adbox_t13_w_backg'><br>"+msg+"<br></div>"    */
/*	z_msgwindow= window.open ("waitmsg.htm", "z_msgwindow", "location=0,status=0,directories=0,scrollbars=0,width=400,height=110");   */
	z_msgwindow= window.open ("waitmsg.htm", "z_msgwindow", "width=400,height=110");
	z_msgwindow.moveTo(550,300);   
	
}

function do_msg_alert(msg)
{
/*	e.g. msg="<br><b>Please Wait<b> while the server is updated ...<br>"             */
	txt="<span class=\'t11b_red\'><br>&nbsp;&nbsp;&nbsp;&nbsp;"+msg+"<br></span>"   ; 
/*	z_msgwindow= window.open ("waitmsg.htm", "z_msgwindow", "location=0,status=0,directories=0,scrollbars=0,width=400,height=110");   */
	document.getElementById("msg_alert").innerHTML=txt;
	UNhideObj("msg_alert");
}   

function wait_button_disabled(whichid)
{
	msg="Please Wait ..." ;         
	var opbutton =document.getElementById(whichid);   
	opbutton.value=msg;
	opbutton.disabled=true;
}
	
function wait_disable_form(whichform) 
{
		if (document.all || document.getElementById) 
			{
			  for (i = 0; i < whichform.length; i++) 
				{
					var tempobj = whichform.elements[i];
					if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
						tempobj.disabled = true;
				}
			}
}			

function disableForm(theform) {
if (document.all || document.getElementById) {
for (i = 0; i < theform.length; i++) 
	{
		var tempobj = theform.elements[i];
		if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
		tempobj.disabled = true;
	}
		setTimeout('alert("Your form has been submitted.  Notice how the submit and reset buttons were disabled upon submission.")', 2000);
		return true;
	}
else {
alert("The form has been submitted.  But, since you're not using IE 4+ or NS 6, the submit button was not disabled on form submission.");
return false;
   }
}
//  End -->
