function refreshImages()
	{
		// Make sure we are using a new rand code.
		var new_url = new String("../show-visualcode.php?");
		// Quick and dirty way of converting decimal to hex
		// Quick and dirty way of converting decimal to hex
		var hexstr = "0123456789abcdef";
		for(var i=0; i < 32; i++)
			new_url = new_url + hexstr.substr(Math.floor(Math.random() * 16), 1);
		document.getElementById("verificiation_image").src = new_url;
}

//-----------------------------------
function getCookie(name) {

var cookiename = name + "=";

var ca = document.cookie.split(';');

for(var i=0;i < ca.length;i++) {

var c = ca[i];

while (c.charAt(0)==' ') c = c.substring(1,c.length);

if (c.indexOf(cookiename) == 0) return c.substring(cookiename.length,c.length);

}

return null;
}
//----------------------------------
//

function clearField(field_id) {
if(field_id.value =="yyyy/mm" ) {
field_id.value = "";
}
} 
/*function clearField(field_id, term_to_clear) {
if (document.getElementById(field_id).value == term_to_clear ) {
document.getElementById(field_id).value = ”;
}
} */


// end clearField()

function updatesum(frm) {
	// update form sum
var d, n = 0;
//
d = Number(frm.amountowing1.value); // convert field value to a number
if (isNaN(d)) d = 0; // if not a number, use zero
n += d; // add to total
//
d = Number(frm.amountowing2.value); // convert field value to a number
if (isNaN(d)) d = 0; // if not a number, use zero
n += d; // add to total
d = Number(frm.amountowing3.value); // convert field value to a number
if (isNaN(d)) d = 0; // if not a number, use zero
n += d; // add to total
//
d = Number(frm.amountowing4.value); // convert field value to a number
if (isNaN(d)) d = 0; // if not a number, use zero
n += d; // add to total
//d = Number(frm.amountowing5.value); // convert field value to a number
//if (isNaN(d)) d = 0; // if not a number, use zero
//n += d; // add to total
//
d = Number(frm.amountowing6.value); // convert field value to a number
if (isNaN(d)) d = 0; // if not a number, use zero
n += d; // add to total

d = Number(frm.amountowing7.value); // convert field value to a number
if (isNaN(d)) d = 0; // if not a number, use zero
n += d; // add to total
//
//
var num = new Number(n);
frm.total.value =num.toFixed(2); // output total
}



function print_form(frm)

{
var url="print-form.php?";

var number_of_elements = frm.elements.length;
for(i=0; i<number_of_elements;i++){

	var el = frm.elements[i];
	if(el.type=="radio"){
		   var checked = false;
		   var group = frm[el.name];
           for (var r = 0; r < group.length; r++){
   		        if ((group[r].checked)){
			 		 url+=el.name+"="+group[r].value+"&";
					 checked=true;
	                 break;
				}

			}
			  if (!checked)
			  {
				 url+=el.name+"=N/A&"; 
			  }

	}
	else {
	url+=el.name+"="+el.value+"&";
	}
}




var display_setting="toolbar=yes, location=no, directories=no, menubar=yes,"; 
    	display_setting+="resizable=1 ,scrollbars=yes, width=800, height=600, left=50, top=5"; 
	
theWin = window.open(url,"",display_setting);
theWin.document.close();
theWin.focus();
/*theWin = window.open("","",display_setting);
theWin.document.write(url);
theWin.focus();
theWin.document.close();*/

}







var panels = new Array();
var tabsOn = new Array();
var tabsOff = new Array();

function setupPanels()
{
	panels[0] = "panel1";
	panels[1] = "panel2";
	panels[2] = "panel3";
	

	
	tabsOn[0] = "step1_on";
	tabsOn[1] = "step2_on";
	tabsOn[2] = "step3_on";
  
	
	tabsOff[0] = "step1_off";
	tabsOff[1] = "step2_off";
	tabsOff[2] = "step3_off";
	
	
	// should be add in IE brower 
	hideControl("errmessage");

		
}

function displayOnTop(self)
{
	if (self != top) top.location = self.location;
}

function switchPanel(activePanelId) 
{	
	var previousPanel;
	var nextPanel;
	/* Begin of Validate- Before move on next panel check input  */
	
	
	if (validate_check(document.frm,activePanelId)==false){return false;}
	  						
	clearErrormsg();
	
				
  /* End of Validate- Before move on Contact panel check input in Decrease Panel or Increase Panel */

   
	for (var i=0; i < panels.length; i++ ) 
	{
		if(panels[i] == activePanelId)
		{
			showControl(panels[i]);
			showControl(tabsOn[i]);
		    hideControl(tabsOff[i]);
			//document.frm.increase_children_covered.focus();
			
			if(i > 0)
			{
				previousPanel = panels[i - 1];
				
				if(i < panels.length - 1)
				{
					nextPanel = panels[i + 1];
				}
				else
				{
					nextPanel = "";
				}
				
			}
			else
			{
				previousPanel = "";
				nextPanel =  panels[1];
			}
						
			if(previousPanel == "")
			{
				hideControl("previous_button");
				hideControl("submit_button");
				hideControl("print_button");
				showControl("next_button");
				
				hideControl("previous_button_top");
				hideControl("submit_button_top");
				hideControl("print_button_top");
				showControl("next_button_top");
			}
			
			if(nextPanel == "")
			{
				hideControl("next_button");	
				showControl("previous_button");
				showControl("submit_button");
				showControl("print_button");
			
				hideControl("next_button_top");	
				showControl("previous_button_top");
				showControl("submit_button_top");
				showControl("print_button_top");
			
			}
			
			if(previousPanel != "" && nextPanel != "")
			{
				hideControl("submit_button");	
				hideControl("print_button");
				showControl("previous_button");
				showControl("next_button");
				
				hideControl("submit_button_top");	
				hideControl("print_button_top");
				showControl("previous_button_top");
				showControl("next_button_top");
			}			
		}
		else
		{
			hideControl(panels[i]);
			showControl(tabsOff[i]);
		    hideControl(tabsOn[i]);
			
		}
	}
	

	document.frm.previousPanel.value = previousPanel;
	document.frm.nextPanel.value = nextPanel;

}
			
			
			
			
			
	
//validate_increase
//input check form name
//Return: true  -  right
//        false -  error 
function validate_check(form,activePanelId)
{
var errorMsg="";
switch (activePanelId) {
   case "panel1":
   	return true;
   case "panel2":
   //check panel1
   
   var errorMsg="Date format (YYYY/MM) Error!."
   var number_of_elements = frm.elements.length;
   for(i=0; i<number_of_elements;i++){
	var checkInputVar = frm.elements[i];
	if(checkInputVar.name.substring(0,8)=="listdate"){
		if (isNotNull(trim(checkInputVar.value))==true){
		if (isDateYYYYMM_YYYY(trim(checkInputVar.value),errorMsg)==false){
	    //errorMsg="Input Error!   1.How many children are covered under the current Order?  cannot be empty.";
		
		checkInputVar.focus();
    	return false;
		}
	}
	}
	
	
	}
	
    	
   
	return true;
	break;

	case "panel3":
     	
   //check panel2
     	return true;
 		break;
   case "panel4":
   //check panel3
  	return true;
	break;
   case "panel5":
   //check panel4
     	return true;
 default:
  	return true;
  } 

return true;

}

// decrease Panel validate check

// Before submit check 

function validateEvaluationRequestInput(form)
{
    	
	//   Name:	contact_name	Text	No
    var checkInputVar=form.contact_name;

   	if (isNotNull(trim(checkInputVar.value))==false){
	//errorMsg="Input Error!   1.How many children are covered under the current Order?  cannot be empty.";
	errorMsg="Input Error! Please enter your Name."
	alert( errorMsg );
	checkInputVar.focus();
    return false;
	}
	//Address:	address	Text	No
  /*  var checkInputVar=form.address;

   	if (isNotNull(trim(checkInputVar.value))==false){
	//errorMsg="Input Error!   1.How many children are covered under the current Order?  cannot be empty.";
	errorMsg="Input Error! Please enter your Address."
	alert( errorMsg );
	checkInputVar.focus();
    return false;
	}

	//City:	city	phone	No
    var checkInputVar=form.city;
   	if (isNotNull(trim(checkInputVar.value))==false){
	errorMsg="Input Error! Please enter City."
	alert( errorMsg );
	checkInputVar.focus();
    return false;
	}

   // Province:  	province	email	yes
    var checkInputVar=form.province;
   	if(checkInputVar.selectedIndex<=0){
	errorMsg="Input Error! Please select a Province."
	alert( errorMsg );
	checkInputVar.focus();
    return false;
	}
*/
	var checkInputVar=form.email;
    if (isNotNull(trim(checkInputVar.value))==false){
	errorMsg="Input Error! Please enter Your Email."
	alert( errorMsg );
	checkInputVar.focus();
    return false;
	}
	
   if (isNotNull(trim(checkInputVar.value))==true){
	 if (isValidEmail(trim(checkInputVar.value))== false ) 
     {
	 errorMsg="Input Error! Please enter right email.";
	 showMessage( errorMsg );
	 checkInputVar.focus();
     return false;
     }
	} 
	
		// check visual code 
   var checkInputVar=form.vcode;
   if (isNotNull(trim(checkInputVar.value))==false){
	errorMsg="Input Error! Please enter Visual verification code. <br> Type the letters shown in the box"
	alert( errorMsg );
	checkInputVar.focus();
    return false;
   }


   var visual_verification_code = getCookie("visual_verification_code");
   

   if (isNotNull(trim(visual_verification_code))==false){
		errorMsg="system errorInput Error! Please enter Your Email."
		alert( errorMsg );
		checkInputVar.focus();
    	return false;
	}
	else {
		if (trim(visual_verification_code)!=trim(checkInputVar.value).toUpperCase()){
			errorMsg="Input Error! Please enter Right Visual verification code. <br> Type the letters shown in the box"
			alert( errorMsg );
			checkInputVar.focus();
    		return false;
			
		}

	}
	
	//  check visual code  end 
	
	
	return true;

 }
  

function clearErrormsg()
{
	  // should be add in IE brower  
   hideControl("errmessage");
	  document.getElementById('errmessage').innerHTML = '';
	  
}


function isNotNull(s)
{
	s=trim(s);
	
	if ((s==null)||(s=="") || (s.lengh==0)){
		return false
	}
	return true;
	
}


 
function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
 }

  

//removes leading and trailing spaces in the string passed in.

function trim( string_to_trim )
{ 
  while (string_to_trim.charAt(0) == " ")
  { 
    // remove leading spaces 
    string_to_trim = string_to_trim.substring(1); 
  } 
  
  while (string_to_trim.charAt(string_to_trim.length - 1) == " ")
  { 
    // remove trailing spaces 
    string_to_trim = string_to_trim.substring(0,string_to_trim.length - 1); 
  } 
  
  return string_to_trim; 
}


//fully replace the alert function

window.alert = function(msg) {
		// should be add in IE brower if hideControl used  
		msg="<p>"+msg+"</p>";
   showControl("errmessage");
   document.getElementById('errmessage').innerHTML = msg;
   /* window.setTimeout(function() {
       document.getElementById('errmessage').innerHTML = '';
   }, 2000); */
   
}

// Show error message 
function showMessage(msg) {
	msg="<p>"+msg+"</p>";
	// should be add in IE brower if hideControl used  
   showControl("errmessage");
   document.getElementById('errmessage').innerHTML = msg;
  }
  
  
  //removes leading and trailing spaces in the string passed in.
function trim( string_to_trim )
{ 
  while (string_to_trim.charAt(0) == " ")
  { 
    // remove leading spaces 
    string_to_trim = string_to_trim.substring(1); 
  } 
  
  while (string_to_trim.charAt(string_to_trim.length - 1) == " ")
  { 
    // remove trailing spaces 
    string_to_trim = string_to_trim.substring(0,string_to_trim.length - 1); 
  } 
  
  return string_to_trim; 
} 

//show div passed in
function showControl(controlId)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		document.getElementById(controlId).style.visibility = "visible";
		document.getElementById(controlId).style.display = "block"; 
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		document.all[controlId].style.visibility = "visible";
		document.getElementById(controlId).style.display = "block"; 
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		document.layers[controlId].visibility = "visible";
		document.getElementById(controlId).style.display = "block"; 
	}
}

//hide div passed in
function hideControl(controlId)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		document.getElementById(controlId).style.visibility = "hidden";
		document.getElementById(controlId).style.display = "none"; 
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		document.all[controlId].style.visibility = "hidden";
		document.getElementById(controlId).style.display = "none"; 
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		document.layers[controlId].visibility = "hidden";
		document.getElementById(controlId).style.display = "none"; 
	}
}


/**
 * DHTML date validation script. 
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;


function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}


function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr,errMsg){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert(errMsg + "The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert(errMsg+"Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert(errMsg+"Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert(errMsg+"Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert(errMsg+ "Please enter a valid date")
		return false
	}
return true
}

function isDateYYYYMM(dtStr,errMsg){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)

	var strYear=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1)

	strYr=strYear
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	
	year=parseInt(strYr)
	if (pos1==-1){
		alert(errMsg + "The date format should be : YYYY/MM")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert(errMsg+"Please enter a valid month")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert(errMsg+"Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos1+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert(errMsg+ "Please enter a valid date")
		return false
	}
return true
}

// check if the date format is YYYY/MM or YYYY
function isDateYYYYMM_YYYY(dtStr,errMsg){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	if (pos1!=-1){
	var strYear=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1)
	}
	else 
	{
		var strYear=dtStr
		var strMonth=""
	}
	
	strYr=strYear
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	
	year=parseInt(strYr)

	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert(errMsg+"Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}


	if (pos1!=-1){
	//if month input
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)

	month=parseInt(strMonth)
	
	if (strMonth.length<1 || month<1 || month>12){
		alert(errMsg+"Please enter a valid month")
		return false
	}
	}

	
	
return true
}




// 
function isValidNumeric(s){
	  if(s.match(/(^-?\d\d*[\.|,]\d*$)|(^-?\d\d*$)|(^-?[\.|,]\d\d*$)/)==null) return false;
	  return true;
}
  //
function isValidAplha(s){
	  if(s.match(/(^[_\-a-z]*\s*[_\-a-z]*$)/gi)==null) return false;
	  return true;
}
 //
 function isValidPhone(s){
	  if(s.match(/(^\(*\d*\)*-*\d*-*\d*$)/)==null) return false;
	  return true;
}

function isInteger(s)
{   var i;
   
  
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}


  
  
// isIntegerInRange (STRING s, INTEGER a, INTEGER b)
  
function isIntegerInRange (s, a, b)
   {   if (isEmpty(s))
         if (isIntegerInRange.arguments.length == 1) return false;
         else return (isIntegerInRange.arguments[1] == true);

      // Catch non-integer strings to avoid creating a NaN below,
      // which isn't available on JavaScript 1.0 for Windows.
      if (!isInteger(s, false)) return false;

      // Now, explicitly change the type to integer via parseInt
      // so that the comparison code below will work both on
      // JavaScript 1.2 (which typechecks in equality comparisons)
      // and JavaScript 1.1 and before (which doesn't).
      var num = parseInt (s);
      return ((num >= a) && (num <= b));
   }

function isIntegerGreaterEqual (s, a)
   {   if (isEmpty(s))
         if (isIntegerInRange.arguments.length == 1) return false;
         else return (isIntegerInRange.arguments[1] == true);

      // Catch non-integer strings to avoid creating a NaN below,
      // which isn't available on JavaScript 1.0 for Windows.
      //if (!isInteger(s, false)) return false;

      // Now, explicitly change the type to integer via parseInt
      // so that the comparison code below will work both on
      // JavaScript 1.2 (which typechecks in equality comparisons)
      // and JavaScript 1.1 and before (which doesn't).
      var num = parseInt (s);
      return ((num >= a));
   }
//


function checkEnter(e){

//e is event object passed from function invocation
var characterCode 
//literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
//document.forms[0].submit() //submit the form
return false
}
else{
return true
}

}

function isValidEmail(s){

if((s.match(/(^[A-Za-z/-9!#-'*+\-/=?_`{-~^]([A-Za-z.-9!#-'*+\-/=?_`{-~^]*[A-Za-z/-9!#-'*+\-/=?_`{-~^])?@([A-Za-z0-9]+\.)+[A-Za-z0-9]+\.?$)/i)==null)) return false;
	  
	  return true;
} 
