/************************************************************** 
                  Validation Script Written by Emadullah Gawai
                          
                         http://www.gawai.8m.com
**************************************************************/
function show_memu(x,y){
if(x=="inline")
 eval(y + '.style.display="none"');
else
 eval(y + '.style.display="inline"');
}

function hide_memu(a,b){
if( (document.getElementById(a).style.display=="inline") || (document.getElementById(b).style.display=="inline") );

document.getElementById(a).style.display="none"
document.getElementById(b).style.display="none"

}


// hide this script from non-javascript-enabled browsers

/* Function that displays status bar messages. */



function MM_displayStatusMsg(msgStr)  { //v3.0
	status=msgStr; document.MM_returnValue = true;
}

/* Functions that finds images. */
function MM_findObj(n, d) { //v3.0
  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); return x;
}
/* Functions that swaps images. */
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/* Functions that handle named groups. */
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

//=========================================================================
//Begin Page Validation

var strAlertMsg = ""
var focusField = ""

function validMailFrm(){
strAlertMsg = ""
focusField = ""
x = document.forms[0];        
    isEmail1('fromEmail','Your Valid Email Address')
    //isEmail('toEmail','Friend Valid Email Address')    
    
   if(strAlertMsg !=""){
         alert("Please correct the following errors:\n___________________________\n\n" + strAlertMsg);
         //eval("x." + focusField + ".focus()");
       return false;
   }
   return true;
}

//================================================================
// validate User Comments
function validContactFrm() {
strAlertMsg = ""
focusField = ""
x = document.forms[1];    
   isText('name','Your Name');
   isEmail('email','Your Valid Email Address');
   isText('subject','Subject Line');
   isEmpty('comments','Message');
   
   if(strAlertMsg !=""){
         alert("Please correct the following errors:\n___________________________\n\n" + strAlertMsg);
       return false;
   }
   return true;
	

}

function validCommentFrm () {
strAlertMsg = ""
focusField = ""
x = document.forms[1];    
   isText('author','Your Name');
   isEmail('email','Your Valid Email Address');
   isEmpty('country','Your country');
   isEmpty('comment','Message');
   isEmpty('urdu_comment_captcha','Security Code');

   if(strAlertMsg !=""){
         alert("Please correct the following errors:\n___________________________\n\n" + strAlertMsg);
       return false;
   }
   return true;
	

}

function isEmpty(strFieldName,strMsg){
    var objFormField = document.forms[1].elements[strFieldName];
    var strValue = objFormField.value;
    strValue = strValue.split(" ").join("")
    if(strValue.length<1){
         strAlertMsg += "- "+ strMsg +" is Required.\n";
    if(!focusField) focusField =""+ strFieldName +"";
         return false;
         }
    return true;
}

//========================================================================
//Validate Us Phone. Ex. (999) 999-9999 or (999)999-9999
function isPhone(strFieldName,strMsg)     {
    var objFormField = document.forms[1].elements[strFieldName];
    var strValue = objFormField.value;
    var objRegExp  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
     if(!objRegExp.test(strValue)){
         strAlertMsg += "- "+ strMsg +" is Required.\n    Example:\n(999)999-9999 or (999) 999-9999\n";
    if(!focusField) focusField=""+ strFieldName +"";
         return false;
         }
    return true;
}
//========================================================================
//Validate US zip code in 5 digit format or zip+4 format. 99999 or 99999-9999
function isZipCode(strFieldName,strMsg)     {
    var objFormField = document.forms[1].elements[strFieldName];
    var strValue = objFormField.value;
    var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
    if(!objRegExp.test(strValue)){
         strAlertMsg += "- "+ strMsg +" is Required.\n";
    if(!focusField) focusField =""+ strFieldName +"";
         return false;
         }
    return true;
}
//==========================================================================
//Validate the Select
function hasSelection(strFieldName,strMsg)     {
    var objFormField = document.forms[1].elements[strFieldName];
    if(objFormField.selectedIndex ==0)     {
         strAlertMsg += "- "+ strMsg +" is Required.\n";
          return false; 
           }
    return true; 
}
//========================================================================
//Validate Check Box
function isChecked(strFieldName,strMsg) {
    var objFormField= document.forms[1].elements[strFieldName];
    var strValue= objFormField.checked;
    if (!strValue) {
         //alert("The \""+ strMsg +"\" box is checked!")
         //} else {
         strAlertMsg += "- "+ strMsg +" is Required.\n";
    if(!focusField) focusField =""+ strFieldName +"";
         return false;
         }
    return true;
}
//========================================================================
//========================================================================
//Validate Radio Button
function checkRadioControl(strFieldName,strMsg){
         var objFormField = document.forms[1].elements[strFieldName]
         intControlLength = objFormField.length
         bolSelected = false;
         for (i=0;i<intControlLength;i++){
         if(objFormField[i].checked){
         bolSelected = true;
         break;
         }
    }     
     if(! bolSelected){
         strAlertMsg += "- "+ strMsg +" is Required.\n";
         return false;
         }
    return true;
}
//========================================================================
//Compare the Fields
function compareFields(strFieldName1,strFieldName2,strMsg){
         var objFormField1= document.forms[1].elements[strFieldName1];
         var objFormField2= document.forms[1].elements[strFieldName2];
         var strValue1= objFormField1.value;
         var strValue2= objFormField2.value;
    if(strValue1 != strValue2){
         strAlertMsg +="The "+ strMsg +" fields do not match, please try again.\n"; 
     if(!focusField) focusField =""+ strFieldName1 +"";
         return false; 
          }
    return true;
}
//========================================================================
//Format Phone Number 9999999999 = (999)999-9999
//Call the function like so onKeyPress="javascript:formatPhone(this);
function formatPhone(objFormField){
    intFieldLength = objFormField.value.length;
    if(intFieldLength == 3){
         objFormField.value = "(" + objFormField.value + ") ";
         return false;
         }
   if(intFieldLength >= 9 && intFieldLength <= 10){
       objFormField.value = objFormField.value + "-";
       return false;
       }
}
//========================================================================


/*****************************************************
%%%%%%%%%%%%******* Developed By :******%%%%%%%%%%%%%%
***************** Emadullah Gawai ********************
************ HTTP://WWW.GAWAI.8M.COM *****************
***************** Text Validator  *******************/

function isText(strFieldName,strMsg) {    
    var objFormField = document.forms[1].elements[strFieldName]
	var strText = objFormField.value;
	var bolValid = true;
	
	if ((strText == "")||(strText==" ")){
		bolValid = false;
	}	
	
	if((strText.substring(0,1)<"a" || strText.substring(0,1)>"z") && (strText.substring(0,1)<"A" || strText.substring(0,1)>"Z"))
		{
			bolValid = false;
		}
		for (var i = 1; i < strText.length; i++)
		{
			var ch = strText.substring(i, i + 1);
			if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch != " "))
			{
				bolValid = false;
			}
		}
	if(!bolValid){
		strAlertMsg += "- "+ strMsg +" is Required.\n";
		if(!focusField) focusField =""+ strFieldName +"";
         }
	return bolValid;
}

/***************************************
************  Email Validator  ******** 
***************************************/
function isEmail(strFieldName,strMsg) {
	var objFormField = document.forms[1].elements[strFieldName]
	var strEmail = objFormField.value;
    	var bolValid = true;
    	
 	var strCount;
 	var noOfAt;
 	strCount = strEmail.split("@");
	noOfAt = strEmail.length - 1;
	
	if (strEmail<1){		
		bolValid = false;		
	}
	
	if (strEmail.indexOf("@")<3){
		bolValid = false;
	}
	
	else if ((strEmail.indexOf(".com")<5)&&(strEmail.indexOf(".org")<5)
		&&(strEmail.indexOf(".gov")<5)&&(strEmail.indexOf(".net")<5)
		&&(strEmail.indexOf(".co")<5)&&(strEmail.indexOf(".tv")<5)
		&&(strEmail.indexOf(".ws")<5)&&(strEmail.indexOf(".am")<5)
		&&(strEmail.indexOf(".nl")<5)&&(strEmail.indexOf(".ru")<5)
		&&(strEmail.indexOf(".in")<5)&&(strEmail.indexOf(".id")<5)
		&&(strEmail.indexOf(".ae")<5)&&(strEmail.indexOf(".de")<5)
		&&(strEmail.indexOf(".kw")<5)&&(strEmail.indexOf(".us")<5)
		&&(strEmail.indexOf(".ns")<5)&&(strEmail.indexOf(".uk")<5)
		&&(strEmail.indexOf(".om")<5)&&(strEmail.indexOf(".ae")<5)
		&&(strEmail.indexOf(".mil")<5)&&(strEmail.indexOf(".edu")<5)){
		bolValid = false;
	}
	
	if((strEmail.substring(0,1)<"a" || strEmail.substring(0,1)>"z") && (strEmail.substring(0,1)<"A" || strEmail.substring(0,1)>"Z"))
	{
		bolValid = false;
	}
	
	for (var i = 1; i < strEmail.length; i++)
	{
		var ch = strEmail.substring(i, i + 1);		
		if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch)  && (ch != "@") && (ch != ".") && (ch != "_") && (ch != "-"))
		{
			bolValid = false;
		}
	}  

	
	if(!bolValid){
		strAlertMsg += "- "+ strMsg +" is Required.\n";
	    	if(!focusField) focusField =""+ strFieldName +"";
	}	
	return bolValid;
	}
	
//***************** Password Validator  *******************/

function isPwd(strFieldName,strMsg) {    
    var objFormField = document.forms[1].elements[strFieldName]
	var strPwd = objFormField.value;
	var bolValid = true;
	
	if ((strPwd == "")||(strPwd==" ")){
		bolValid = false;
	}	
	
	if((strPwd.substring(0,1)<"a" || strPwd.substring(0,1)>"z") && (strPwd.substring(0,1)<"A" || strPwd.substring(0,1)>"Z"))
		{
			bolValid = false;
		}
		for (var i = 1; i < strPwd.length; i++)
		{
			var ch = strPwd.substring(i, i + 1);
			if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && (ch != " "))
			{
				bolValid = false;
			}
		}
	if(!bolValid){
		strAlertMsg += "- "+ strMsg +" is Required.\n";
		if(!focusField) focusField =""+ strFieldName +"";
         }
	return bolValid;
}


/*********************************
******   Reg Key Validation  *****
*********************************/
function validateKey(){
strAlertMsg = ""
focusField = ""
x = document.forms[1];    
    isEmail('ID','Valid Email Address')
    isNumerics('key','Authorisation Key [Numbers Only]')
    
   if(strAlertMsg !=""){
         alert("Please correct the following errors:\n___________________________\n\n" + strAlertMsg);
         eval("x." + focusField + ".focus()");
       return false;
   }
   return true;
}


/****************************
***    Numeric Validation ***
****************************/
function isNumerics(strFieldName,strMsg) {    
    var objFormField = document.forms[1].elements[strFieldName]
	var intText = objFormField.value;
	var bolValid = true;
	
	if ((intText == "")||(intText==" ")){
		bolValid = false;
	}	
	
	if((intText.substring(0,1)<"0" || intText.substring(0,1)>"9"))
		{
			bolValid = false;
		}
		for (var i = 1; i < intText.length; i++)
		{
			var ch = intText.substring(i, i + 1);
			if ((ch < "0" || "9" < ch))
			{
				bolValid = false;
			}
		}
	if(!bolValid){
		strAlertMsg += "- "+ strMsg +" is Required.\n";
		if(!focusField) focusField =""+ strFieldName +"";
         }
	return bolValid;
}



/**************************************
*********** Update Validation **********
**************************************/

function updatePassword(objFrm)
{
	var str = objFrm.newpass.value;
	var str2 = objFrm.oldpass.value;
	if ((str == "") ||(str2 == ""))
	{
		alert("\nThe PASSWORD field is blank.\nPlease enter.")		
		return false;
	}
	var str2 = objFrm.conpass.value;
	if (str != str2)
	{
		alert("\nPasswords typed do not match, please re-enter your passwords.\n\n");
		objFrm.conpass.select();
		return false;
	}
	return true;
}

//========================================================================
//Compare the Fields
function compareFields(strFieldName1,strFieldName2,strMsg){
         var objFormField1= document.forms[1].elements[strFieldName1];
         var objFormField2= document.forms[1].elements[strFieldName2];
         var strValue1= objFormField1.value;
         var strValue2= objFormField2.value;
    if(strValue2 != strValue1){
         strAlertMsg +="- "+ strMsg +" do not match with password"; 
     if(!focusField) focusField =""+ strFieldName1 +"";
         return false; 
          }
    return true;
}


//================================================================



//==========================================================================
function popupWin(url){		
	window.open(url,"sahilOnline","height=700,width=750,top=0,left=0,scrollbars=yes,resizable=yes,toolbar=no")
	
}

function TafWin(url){
	var myPopup = window.open(url,"sahilOnline1","height=400,width=640,top=5,left=5,scrollbars=no,resizable=no,toolbar=no,directory=no")
	myPopup.focus();

}

function printWin(url){
	var myPopup = window.open(url,"sahilOnline2","height=550,width=700,top=0,left=0,scrollbars=yes,resizable=no,toolbar=no,directory=no")
	myPopup.focus();

}

function report(url){
	var myPopup = window.open(url,"sahilOnline3","height=500,width=600,top=50,left=50,scrollbars=yes,resizable=no,toolbar=no,directory=no")
	myPopup.focus();

}


/*************************************
********* Show Flash Movie *********
*************************************/

function showFlash(strId, strMovie, strBgColor, numWidth, numHeight, getsURL, winTarget) {
	if ( plugin ) {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ');
		document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,42,0" ');
		document.write('id="' + strId +'" width="' + numWidth + '" height="' + numHeight + '">');
		document.write('<param name="movie" value="' + strMovie + '.swf?clickTag=' + getsURL + '&OpenTag=' + winTarget +'">');
		document.write('<param name="quality" value="high">');
		document.write('<param name="bgcolor" value="' + strBgColor + '">');
		document.write('<param name="menu" value="false">');
		document.write('<param name="wmode" value="transparent">');	
		document.write('<embed name="product" src="' + strMovie + '.swf?clickTag=' + getsURL + '&OpenTag=' + winTarget +'" quality="high" bgcolor="' + strBgColor + '" swLiveConnect="true" ');
		document.write('width="' + numWidth + '" height="' + numHeight + '" type="application/x-shockwave-flash" ');
		document.write('pluginspage="http://www.macromedia.com/go/getflashplayer">');
		document.write('</embed>');
		document.write('</object>');
	}
	if (! plugin ) {
		//document.write('<a href="' + getsURL + '" target="' + winTarget + '">');
		//document.write('<img border="0" src="' + strMovie + '.gif" width="' + numWidth + '" height="' + numHeight + '">');
		//document.write('</a>');
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ');
		document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,42,0" ');
		document.write('id="' + strId +'" width="' + numWidth + '" height="' + numHeight + '">');
		document.write('<param name="movie" value="' + strMovie + '.swf?clickTag=' + getsURL + '&OpenTag=' + winTarget +'">');
		document.write('<param name="quality" value="high">');
		document.write('<param name="bgcolor" value="' + strBgColor + '">');
		document.write('<param name="menu" value="false">');
		document.write('<param name="wmode" value="transparent">');	
		document.write('<embed name="product" src="' + strMovie + '.swf?clickTag=' + getsURL + '&OpenTag=' + winTarget +'" quality="high" bgcolor="' + strBgColor + '" swLiveConnect="true" ');
		document.write('width="' + numWidth + '" height="' + numHeight + '" type="application/x-shockwave-flash" ');
		document.write('pluginspage="http://www.macromedia.com/go/getflashplayer">');
		document.write('</embed>');
		document.write('</object>');
		
	}
	
}

/*************************************
********* New Flash Movie *********
*************************************/
function showNewFlash(strId, strMovie, strBgColor, numWidth, numHeight, getsURL, winTarget) {
	if ( plugin ) {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ');
		document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,42,0" ');
		document.write('id="' + strId +'" width="' + numWidth + '" height="' + numHeight + '">');
		document.write('<param name="movie" value="' + strMovie + '.swf?clickTag=' + getsURL + '&winTag=' + winTarget +'">');
		document.write('<param name="quality" value="high">');
		document.write('<param name="bgcolor" value="' + strBgColor + '">');
		document.write('<param name="menu" value="false">');
		document.write('<param name="wmode" value="transparent">');	
		document.write('<embed name="product" src="' + strMovie + '.swf?clickTag=' + getsURL + '&winTag=' + winTarget +'" quality="high" bgcolor="' + strBgColor + '" swLiveConnect="true" ');
		document.write('width="' + numWidth + '" height="' + numHeight + '" type="application/x-shockwave-flash" ');
		document.write('pluginspage="http://www.macromedia.com/go/getflashplayer">');
		document.write('</embed>');
		document.write('</object>');
	
	}
	if (! plugin ) {
		/*document.write('<a href="' + getsURL + '" target="' + winTarget + '">');
		document.write('<img border="0" src="' + strMovie + '.gif" width="' + numWidth + '" height="' + numHeight + '">');
		document.write('</a>');*/
		
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ');
		document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,42,0" ');
		document.write('id="' + strId +'" width="' + numWidth + '" height="' + numHeight + '">');
		document.write('<param name="movie" value="' + strMovie + '.swf?clickTag=' + getsURL + '&winTag=' + winTarget +'">');
		document.write('<param name="quality" value="high">');
		document.write('<param name="bgcolor" value="' + strBgColor + '">');
		document.write('<param name="menu" value="false">');
		document.write('<param name="wmode" value="transparent">');	
		document.write('<embed name="product" src="' + strMovie + '.swf?clickTag=' + getsURL + '&winTag=' + winTarget +'" quality="high" bgcolor="' + strBgColor + '" swLiveConnect="true" ');
		document.write('width="' + numWidth + '" height="' + numHeight + '" type="application/x-shockwave-flash" ');
		document.write('pluginspage="http://www.macromedia.com/go/getflashplayer">');
		document.write('</embed>');
		document.write('</object>');
		
	}
	

}

//**************** <    Flash Detector   > ***************
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
	plugin = parseInt(plugin.description.substring(plugin.description.indexOf(".")-1)) >= 3;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && navigator.userAgent.indexOf("Windows")>=0) {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('plugin = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4")))\n');
	document.write('if ( plugin <= 0 ) then plugin = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5")))\n');
	document.write('if ( plugin <= 0 ) then plugin = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")))\n');
	document.write('<\/SCR' + 'IPT\> \n');
}

//**************** </   Flash Detector   > ***************

