// JavaScript Document

function OpenWindow( page, target )
{
	var pageProp= "toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes";
	
	window.open( page, target, pageProp );
}

function OpenPopup(page, width, height )
{
	var pageProp= "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width="+ width +", height="+ height +", top=50, left=50";
	
	window.open(page,"",pageProp);
}

function ConfirmLink( theLink, question )
{
	var is_confirmed = confirm(question);
	if (is_confirmed) {
		theLink.href += '&is_js_confirmed=1';
	}

	return is_confirmed;
}

function ConfirmAction( theLink, question )
{
	var is_confirmed = confirm(question);
	if (is_confirmed) {
		return true;
	}

	return false;
}

function ShowMsg( msg )
{
	alert(msg);
}

<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->

function SincButtonWithCheck( idCheckBox, idButton )
{
	var button = document.getElementById(idButton);
	var check = document.getElementById(idCheckBox);
	
	button.disabled = check.checked;	
}

function CompareText(txt1, txt2)
{
    if (txt1.length != txt2.length){return false;}
    cont1=0;cont2=0;
    while (cont1 < txt1.length && cont2 < txt2.length)
    {
    	if (txt1[cont1] != txt2[cont2])
		    {
			   return false;
			}
        cont1++;cont2++;
    }
    return true;
}
function Compare(id_txt1, id_txt2, id_location)
{
    if  (document.getElementById(id_txt1).value.length==0 ||  document.getElementById(id_txt2).value.length==0)
    {
        document.getElementById(id_location).src='images/no.png';
        document.getElementById(id_location).style.display='';
        return false;
    }

    if (CompareText(document.getElementById(id_txt1).value, document.getElementById(id_txt2).value))
    {
        document.getElementById(id_location).src='images/valid.png';
        document.getElementById(id_location).style.display='';
        return true;
    }
    else
    {
        document.getElementById(id_location).src='images/no.png';
        document.getElementById(id_location).style.display='';
        return false;
    }
}

function Refresh(ref, id)
{
    if(document.getElementById(ref).value != 186)
    {
        document.getElementById(id).disabled=true;
    }
    else
    {
        document.getElementById(id).disabled=false;
    }
    return true;
}


function getYear(d)
{
    return (d < 1000) ? d + 1900 : d;
}
function isDate (day, month, year)
{
    // month argument must be in the range 1 - 12
    month = month - 1; // javascript month range : 0- 11
    var tempDate = new Date(year,month,day);
    if ( (getYear(tempDate.getYear()) == year) && (month == tempDate.getMonth()) && (day == tempDate.getDate()) )
            return true;
        else
            return false;
}

function checkDate(id)
{
    var d;
    Form = document.getElementById(id);
    if(isDate(Form.day.value, Form.month.value, Form.year.value))
    {
        document.getElementById("date_status").src ='images/valid.png';
        document.getElementById("date_status").style.display='';
        d = Form.day.value+"-"+Form.month.value+"-"+Form.year.value;
        return true;
    }
    else
    {
        document.getElementById("date_status").src='images/no.png';
        document.getElementById("date_status").style.display='';
        return false
    }
}

function checkPostal(id)
{
    form = document.getElementById(id);
    val = parseInt(form.postal_code.value);

    if (isNaN(val))
    {
        document.getElementById("postal_status").src='images/no.png';
        document.getElementById("postal_status").style.display='';
        return false;
    }else  if (val > 0)
            {
                document.getElementById("postal_status").src='images/valid.png';
                document.getElementById("postal_status").style.display='';
                return true;
            }
            else
            {
                document.getElementById("postal_status").src='images/no.png';
                document.getElementById("postal_status").style.display='';
                return false;
            }

}

function checkState()
{
    if((document.getElementById("country").value == 186) && (document.getElementById("state").value == 0))
    {
        document.getElementById("state_status").src='images/no.png';
        document.getElementById("state_status").style.display='';
        return false;
    }
    else
    {
        document.getElementById("state_status").src='images/valid.png';
        document.getElementById("state_status").style.display='';
        return true;
    }
}

function checkAll()
{

  if (Compare("email1", "email2","email_status") && Compare("pass1", "pass2","pass_status") &&
        checkPostal("Form1") && checkDate("Form1") && checkState())
  {

    return true;
  }
  else
  {
    alert("Error: Check Form");
    return false
  }

}

 function NoEmpty(id,id_status)
{
  if(document.getElementById(id).value != "")
    {
        document.getElementById(id_status).src='images/valid.png';
        document.getElementById(id_status).style.display='';
        return true;
    }
    else
    {
        document.getElementById(id_status).src='images/no.png';
        document.getElementById(id_status).style.display='';
        return false;
    }
}

function checkInfo()
{

  if (NoEmpty("email1","email1_status") && NoEmpty("pass1","pass1_status")  &&
        checkPostal("Form1") && checkDate("Form1") && checkState())
  {

    return true;
  }
  else
  {
    alert("Error: Check Form");
    return false
  }

}
