// GENERAL FUNCTIONS



/************************************************
DESCRIPTION: Validates that a string contains a
  valid email pattern.

 PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) or valid country suffix.
*************************************************/

function validateEmail( strValue) {
var objRegExp  = /(^[a-z]([a-z_\-\.]*)@([a-z_\-\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\-\.]*)@([a-z_\-\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;

  //check for valid email
  return objRegExp.test(strValue);
}

/*********************************************************/





function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  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=MM_findObj(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+='- '+ParseVar(nm)+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+ParseVar(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+='- '+ParseVar(nm)+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+ParseVar(nm)+' is required.\n'; }
  } if (errors) alert('Please make sure the following fields are correct:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function Fill_Selection_Current_Date(){
	var Current_Date = new Date();
	var Year = Current_Date.getFullYear();
	var Month = Current_Date.getMonth()+1;
	// set starting/ending month
	var Obj_Month= document.product['expmonth'];
	var Obj_Year = document.product['expyear'];
	for (i=0; i<= Obj_Month.options.length; i++){
		if (Obj_Month.options[i].value == Month){
			Obj_Month.options[i].selected = true;
			break;
		}
	}
	for (i=0; i<= Obj_Year.options.length; i++){
		if (Obj_Year.options[i].value == Year.toString().slice(2)){
			Obj_Year.options[i].selected = true;
			break;
		}
	}
}

function Select_List_Item(The_Form_Ref,List_Num){
	The_Form_Ref.options[List_Num].selected = true;
}

function Delete_Options(The_Form_Ref){
	//var Form_Ref = document.form1['payments_amount'];
	var Form_Ref = The_Form_Ref;
	var Length = Form_Ref.options.length;
	for (i=0; i<Length; i++){
		Form_Ref.options[0] = null;
	}
}

// options array list - used in Generate_Options, Generate_Option

var Text = new Array("UPS","Standard");

// generate options according to options array
function Generate_Options(The_Form_Ref,Amount){

	Delete_Options(The_Form_Ref);		// first delete current options
//	var Form_Ref = document.form1['payments_amount'];
	var Form_Ref = The_Form_Ref;
	var def1 = false;
	var Selected = false;
	for (i=0; i<Amount; i++){
	  var New_Option = new Option(Text[i], Text[i], def1, Selected);		
	  var Length = Form_Ref.length;
	  Form_Ref.options[Length] = New_Option;
//	  Form_Ref.options[length].selected = false
	}
}


function Generate_Single_Option(The_Form_Ref,The_Option){
	Delete_Options(The_Form_Ref);		// first delete current options
//	var Form_Ref = document.form1['payments_amount'];
	var Form_Ref = The_Form_Ref;
	var def1 = false;
	var Selected = false;
	  var New_Option = new Option(Text[The_Option], Text[The_Option], def1, Selected);		
	  var Length = Form_Ref.length;
	  Form_Ref.options[Length] = New_Option;
//	  Form_Ref.options[length].selected = false
}

/*******************************************************************************
 open window function
********************************************************************************/
function Open_Window(param,w,h) { 
//v2.0
	var size="";
	(w==undefined)?size = 'width=700':size='width='+w;
	(h==undefined)?size+=',height=500':size+=',height='+h;
	var features;
	features = size+"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=0,fullscreen=no";
	  var Popup1 = window.open(param,"window2",features);
	  Popup1.focus();
}


function show() {
	document.all["h1"].style.visibility="visible";
}
function out() {
	document.all["h1"].style.visibility="hidden";
}
	
function Submit(){
	MM_validateForm('fullname','','R','email','','RisEmail','phone','','R');
	if  (document.MM_returnValue){
		document.product.submit();
	}
}

function ParseVar(nm){
	if (nm == "fullname"){
		return  "Full Name";
	} else if (nm == "email"){
		return  "Email Address";
	} else if (nm == "phone"){
		return  "Phone Number";
	}
}	

	
function SubmitForm(){
	var value1,value2,value3;
	thisForm = document.forms["product"];
	thisValue = thisForm.fullname.value;
	if (thisValue.length!=0 || thisValue!="" ){
		value1 = true;
	} else {
		alert("please fill in your full name");
	}
	thisValue = thisForm.email.value;
	if (thisValue.length > 4){
		value2 = true;
	} else {
		alert("please fill in your email address");
	}
	thisValue = thisForm.message.value;
	if (thisValue.length!=0 || thisValue!="" ){
		value3 = true;
	} else {
		alert("please fill in your message");
	}
	if (value1 && value2 && value3) {
		thisForm.submit();
	}
}


function ChangeFeature(THIS,url){
//	alert(THIS.options[THIS.selectedIndex].value);
	url+="&Feature1="+THIS.options[THIS.selectedIndex].value;
	location.href=url;
}