
/// variable & method to create ajax request
var http;
var browser = navigator.appName;
function create_Request_Object() {
    var requestObj = null;
    var browser = navigator.appName;
    // code for Mozilla, etc.
	if (window.XMLHttpRequest)
 	{
	  requestObj = new XMLHttpRequest()
	}
	// code for IE
	else if (window.ActiveXObject)
	{
	  requestObj = new ActiveXObject("Microsoft.XMLHTTP")
	}
	if (requestObj == null)
  	{
	  alert("Your browser does not support XMLHTTP.")
  	}
    return requestObj;       

}
///End variable & method to create ajax request


//Disable right click script
var message="right-click has been disabled";
function clickIE() {if (document.all) {(message);return false;}}

function clickNS(e) 
{
	if(document.layers||(document.getElementById&&!document.all))
	{

	if (e.which==2||e.which==3) {(message);return false;}
	}
}

if(document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else
{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false") 
//End Disable right click script


//disable Copy paste
function fncKeyStop(obj) 
{
    var ctrl = typeof event.modifiers == 'undefined' ?
    event.ctrlKey : event.modifiers & Event.CONTROL_MASK;
    var v = typeof event.which == 'undefined' ?
    event.keyCode == 86 : event.which == 86;
	 if ( ctrl && v ) 
	 {
	    obj.value = '';
	    return false;
	}
 return true;

}
//End disable Copy paste


//disable Paste & it's workss only on windows
function disablePaste()
{
setInterval("ccd();", 100);
}

function clearData()
{
	window.clipboardData.setData('text','') 
}

function ccd(){
if(clipboardData){clipboardData.clearData();}
}

function autoCompOff(obj)
{
obj.setAttribute("autocomplete","off");
}
//End disable Paste


//method to validate numeric field
function chkNumeric(val)
{
	if(isNaN(val))
	return false;
	else return true;

}
//End method to validate numeric field

//method to validate email
function verifyemail_check(str) 
{ 
	   if(!str.match(/^[\w]{1}[\w\.\-_]*@[\w]{1}[\w\-_\.]*\.[\w]{2,6}$/i))
	   return false; 
	   else
	   return true; 

}

function chkmailStr(str) 
{
	if(!str.match(/^[_a-z0-9,@.]*$/i))
	return false;
	else
	return true;

}
//End method to validate email

//method to check alphanumiric values	
function chkAlphaNum(str) 
{
	if(!str.match(/^[_a-z0-9-]*$/i))
 	return false;
	else
	return true;

}
//End method to check alphanumiric values	

//method to validate datefield
function validateDate(fld) {

    var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;

    var errorMessage = 'Please enter valid date as month, day, and four digit year.\nYou may use a slash, hyphen or period to separate the values';

	var dt=(fld.value).trim();

    if ((dt.match(RegExPattern)) && (fld.value!='')) {

        //alert('Date is OK'); 

    } else {

        alert(errorMessage);

        fld.focus();

    } 

}
//end method to validate datefield

/// method to trim string
String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
///End  method to trim string


//method to remove white space from in between a string
function rmWhiteSpace(val)
{
	var str =val;
	str = str.replace(/\s+/g,'');
	return str;
}



// method to get selected index of a combobox,listbox 
function getIndex(obj)
 {
   return(obj.selectedIndex);
  }
//End method to get selected index of a combobox,listbox 
  

//function to validate postal code of us and us governed countries and canada
function checkpostalcode(countryObj,code_obj )
 {
	 var country=countryObj.options[getIndex(countryObj)];
		 if(country=='CA')
		 {
			codeRegex =/^([AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]\d[A-Za-z]\s?\d[A-Za-z]\d)$/;
			if( !code_obj.value.match( codeRegex ) )
				{
				alert( 'Postal code is invalid.' );
				code_obj.value='';
				code_obj.focus();
				 return false;
				}
  		  	 else
			 {return true;}
	     }
		 else
		 {
			if(country.value=='US'|| country.value=='AS'|| country.value=='GU'|| country.value=='MH'|| country.value=='FM'|| country.value=='MP'||country.value=='PW'||country.value=='PR'|| country.value=='VI' )
				{
					codeRegex =/^\d{5}(-\d{4})?$/;
					if( !code_obj.value.match( codeRegex ) )
					{
						alert( 'Postal code is invalid' );
						code_obj.value='';
				        code_obj.focus();
						return false;
					}
					else
					{
						return true;
					}
				}
			 }
			return true;

}
//End function to validate postal code of us and us governed countries and canada

//function to show/hide Loading image
function displayLoadingImg(displayProperty)
{
document.getElementById('loading').style.display=displayProperty;	
}
//End function to show/hide Loading image


//function to show/hide message box
function closeMsg()
{
displayMsg('none');	
}
//function to show/hide message box


//This function use the ajax hint.Set the display msg. & function to position loading img & function to position messageBox & //function to set height  & width
function displayMsg(displayProperty)
{
document.getElementById('outerContainer').style.display=displayProperty;		
document.getElementById('msgBox').style.display=displayProperty;	
}
//function to position loading img
function positionLoadingImg(divID,leftVal,topVal)
{
document.getElementById('loading').style.left=(document.getElementById(divID).offsetLeft+document.getElementById(divID).offsetWidth-leftVal)+"px";
 document.getElementById('loading').style.top=(document.getElementById(divID).offsetTop+topVal)+"px";
}
//function to position messageBox 
function positionMsg(leftVal,topVal)
{
document.getElementById("msgBox").style.left=parseInt((pageWidth()/2)-leftVal)+"px";
document.getElementById("msgBox").style.top=parseInt((pageHeight()/2)-topVal)+"px";
document.getElementById("outerContainer").style.width=parseInt(pageWidth()-12)+"px";
}
//function to set height 
function pageHeight() 
{return window.innerHeight != null? window.innerHeight: document.body != null? document.documentElement.clientHeight:null;}
//function to set width 
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;}

//End This function use the ajax hint.Set the display msg. & function to position loading img & function to position messageBox & //function to set height  & width
function chkNum(obj){

obj.value = obj.value.replace(/[^0-9 -]/g,'') // numbers only

}

function chkDecimal(obj){

obj.value = obj.value.replace(/[^0-9 .]/g,'') // decimal only

}
function chkNumChar(obj){
obj.value = obj.value.replace(/[^0-9 a-z A-Z -]/g,'') // numbers and characters only

}
function chkChar(obj){

obj.value = obj.value.replace(/[^a-z A-Z]/g,'') // numbers and characters only

}

function chkZip(obj){

obj.value = obj.value.replace(/[^0-9 a-z A-Z]/g,'') // numbers and characters only

}
function waterMark(id)
{
	if(id.value.trim()=="xxx-xxx-xxxx")
	{
		id.value='';	
	}
	else if(id.value.trim()=="")
	{		
		id.value="xxx-xxx-xxxx";
	}
	
}
function doSSN(id)
{
	if(id.value.trim()=="xxx-xx-xxxx")
	{
		id.value='';	
	}
	else if(id.value.trim()=="")
	{		
		id.value="xxx-xx-xxxx";
	}
	
}

function waterDOB(id)
{
	if(id.value.trim()=="mm-dd-yyyy")
	{
		id.value='';	
	}
	else if(id.value.trim()=="")
	{		
		id.value="mm-dd-yyyy";
	}
	
}
function chkPhone(id){
	
	var phone_format =/^\d{3}(-\d{3})(-\d{4})?$/;
	var ph=id.value;
	if(!ph.match(phone_format) || ph=='xxx-xxx-xxxx' || ph.length < 12)
	{
	//alert("This is not a valid phone number. Please input value like xxx-xxx-xxxx");
	//document.getElementById(id).focus()
	return false
	}
	else
	return true; 
}

function chkSsn(id){
	
	var ssn_format =/^\d{3}(-\d{2})(-\d{4})?$/;
	var ssn=id.value;
	if(!ssn.match(ssn_format) || ssn=='xxx-xx-xxxx' || ssn.length < 11)
	{
	//alert("This is not a valid phone number. Please input value like xxx-xxx-xxxx");
	//document.getElementById(id).focus()
	return false
	}
	else
	return true; 
}

function chkDoB(id){
	
	var dob_format =/^\d{2}(-\d{2})(-\d{4})?$/;
	var dob=id.value;
	if(!dob.match(dob_format) || dob=='xx-xx-xxxx' || dob.length < 10)
	{
	//alert("This is not a valid phone number. Please input value like xxx-xxx-xxxx");
	//document.getElementById(id).focus()
	return false
	}
	else
	return true; 
}

function textCounter(field,cnt,maxlimit) 
{
	var charcnt = field.value.length;        
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}
	else { 
		document.getElementById(cnt).value=(maxlimit-charcnt)
		//document.getElementById("dispcnt").innerHTML=(maxlimit-charcnt);
	}
}

function fnCancel()
{
var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
alert(sPage);
window.location=sPage;
}

function chkactive(id)
{
//alert('idris');
	if(id.checked==true)
	{
		id.value=1;
	}
	else
	{
		id.value=0;
	}
  //  alert(id.value);
}


function fnloginValidate()
{
 if(document.getElementById("loginName").value.trim()=="" ||document.getElementById("loginName").value.trim()==null)
 {
 alert('Please enter user name !');
 document.getElementById("loginName").focus();
 return false;
 }
 else   if(document.getElementById("pwd").value.trim()=="" ||document.getElementById("pwd").value.trim()==null)
 {
 alert('Please enter password !');
 document.getElementById("pwd").value='';
 document.getElementById("pwd").focus();
 return false;
 }
 else
 {
 return true;
 }
}

function fnreturnState(id,stateId,width,divId)
{	
	
	  
		http = create_Request_Object();//from common.js
		if(!http)
		{
			alert("http if access");
		}
		var url="returnstate.php?id="+id.value+"&stateId="+stateId+"&width="+width+"&sid="+Math.random();
		 http.onreadystatechange=function()
		{
			if(http.readyState < 4)
			{
			//document.getElementById("loading").innerHTML="<img src='../images/loading.gif'  border='0'/>&nbsp;Please wait...";
			 
			}
			if(http.readyState == 4)
			{
			//	document.getElementById("loading").innerHTML='';
				document.getElementById(divId).innerHTML=http.responseText;
			}
		}
		http.open("GET",url,true);	
		http.send(null);
}