function loadingapp()
{
	if(document.getElementById("transLoading")){
		document.getElementById("transLoading").style.display = 'none';
	}
}
function trMouseOver(obj) 
{
	lastColor = obj.style.backgroundImage;
	obj.style.backgroundImage="url("+WWWROOT+"/workshop/images/row_bg_new.gif)";
//	obj.style.backgroundImage = WWWROOT+'/workshop/images/bg_heading.gif';
}
function hideMessageDiv()
{
	document.getElementById("ShowMessage").style.display = 'none';	
}
function trMouseOut(obj) 
{
	obj.style.backgroundImage = lastColor;
}
function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
function isValidEmail(el)
{        
		var str=el;
		var filter=/^([\w-\.\+]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

		var testresults;
		if (filter.test(str))
				testresults=true;
		else 
				testresults=false;
		return (testresults);
}

function isHaveSpecialChars(str)
{        
	 var iChars = "!@#$%^&*()+=[]\\\';,/{}|\":<>?";
	  for (var i = 0; i < str.length; i++) 
	  {
  		if (iChars.indexOf(str.charAt(i)) != -1)
  			return true;
		else
			return false;
 	 }
}
function isHaveSpecialCharsComma(str)
{        
	 var iChars = "!@#$%^&*()+=[]\\\';/{}|\":<>?";
	  for (var i = 0; i < str.length; i++) 
	  {
  		if (iChars.indexOf(str.charAt(i)) != -1)
  			return true;
		else
			return false;
 	 }
}
function isHaveSpecialCharsHTML(str)
{        
	 var iChars = "!@#$^&*()+=[]\\\';,/{}|\":?";
	  for (var i = 0; i < str.length; i++) 
	  {
  		if (iChars.indexOf(str.charAt(i)) != -1)
  			return true;
		else
			return false;
 	 }
}
function CompareDates(txtAuctionSDate, txtAuctionEDate, Caption1, Caption2)
 {
	 //alert(txtAuctionSDate.value.length);
	//alert(txtAuctionEDate.value.length);                
	//return false;
 if(txtAuctionSDate.length!=0 && txtAuctionEDate.length!=0 )
	{
	  var StartDate = txtAuctionSDate;
	  var EndDate = txtAuctionEDate;
	 
	  var arrStart = StartDate.split("-");
	  var arrEnd = EndDate.split("-");          
	  
  if(parseInt(arrEnd[2])<parseInt(arrStart[2]))
		{
		 //alert( Caption1 + ' should be less than or equal to ' + Caption2 + '.' );
		  return false; 
		}
  else if(parseInt(arrEnd[2])==parseInt(arrStart[2]))
	{
		if(parseInt(arrEnd[0])<parseInt(arrStart[0]))
		{
				 //alert( Caption1 + '  should be less than or equal to ' + Caption2 + '.' );
				 return false;
		}
	   else if(parseInt(arrEnd[0])==parseInt(arrStart[0]))        
		{
			  if(arrEnd[1]<=arrStart[1])
				{
				//alert( Caption1 + ' should be less than or equal to ' + Caption2 + '.' );
				return false;
				}
			  else return true;                        
		 }
		 else return true;
	}		
   else return true;                        
 }
 else
 {
	return true;
 } 
} 

//This function does not allow equality of two dates also.
//For Used In These Fils: ListNewsletter.php.
function CompareDatesEquality(txtAuctionSDate, txtAuctionEDate, Caption1, Caption2)
 {
 //alert(txtAuctionSDate.value.length);
//alert(txtAuctionEDate.value.length);                
//return false;
 
 if(txtAuctionSDate.length!=0 && txtAuctionEDate.length!=0 )
	{
	  var StartDate = txtAuctionSDate;
	  var EndDate = txtAuctionEDate;
	 
	  var arrStart = StartDate.split("-");
	  var arrEnd = EndDate.split("-");          
	  
  if(arrEnd[2]<arrStart[2])
	{
	// alert('You must select a future date.');
	  return false; 
	}
  else if(arrEnd[2]==arrStart[2]) 
	{
		if(parseInt(arrEnd[0])<parseInt(arrStart[0]))
		{
				// alert('You must select a future date.');
				 return false;
		}
	   else if(parseInt(arrEnd[0])==parseInt(arrStart[0]))        
		{
			  if(arrEnd[1]<=arrStart[1])
				{
				//alert('You must select a future date.');
				return false;
				}
			    else return true;
		 }
		 else return true;
	}		
   else return true;                        
 }
 else
 {
	return true;
 } 
} 


	function IsEmpty(aTextField) {

		var regexp = /^(\s)*$/

		if(regexp.test(aTextField.value)){
			return "YES";

		}else{
			return "NO";
		}

	}//IsEmpty
function TestFileType( fileName, fileTypes )
{
	if (!fileName)
		return 1;
	
	dots = fileName.split(".")
	//get the part AFTER the LAST period.
	fileType = "." + dots[dots.length-1];
	
	if(fileTypes.join(".").indexOf(fileType) == -1)
	{
		//alert("Please upload only files with extension: \n\n" + (fileTypes.join(" .")) + "\n\nPlease select a new file and try again.");
		alert("Please upload only file with extension: \n(" + (fileTypes.join(" ."))+")" );
		return 0;
	}
	else
	{
		return 1;
	}
	return 0;

}
function TestFileTypeFront( fileName, fileTypes )
{
	if (!fileName)
		return 1;
	
	dots = fileName.split(".")
	//get the part AFTER the LAST period.
	fileType = "." + dots[dots.length-1];
	
	if(fileTypes.join(".").indexOf(fileType) == -1)
	{
		//alert("Please upload only files with extension: \n\n" + (fileTypes.join(" .")) + "\n\nPlease select a new file and try again.");
		//alert("Please upload only file with extension: \n(" + (fileTypes.join(" ."))+")" );
		return 0;
	}
	else
	{
		return 1;
	}
	return 0;

}
function isValidZip(zipcode)
{
		if (zipcode!=""){

		var numericExpression = /^[0-9a-zA-Z\+\-\s]{2,}$/;
		if(zipcode.match(numericExpression)){
			 return true;
		}else{
			return false;
		}		 
		 
		 
	}


}
function setCookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
function isValidUrl(url)
{        
        var pattern = /http:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
        return pattern.test(url);
}
function ClearErrorMessage(val, DivId, ObjectName, Validate, pstrClassName)
{
	
	value = document.getElementById(ObjectName).value;
	if(trim(val)!='')
	{
		document.getElementById(DivId).style.display = 'none';
		if(document.getElementById(ObjectName) && pstrClassName!=1)
		{
			document.getElementById(ObjectName).className="form-input";
		}
	}
	if(Validate=='FirstName')
	 {
		 var valFirstName=document.getElementById('txtFirstName').value;
		 if(value == "")
		 {
			document.getElementById(DivId).style.display = '';
			document.getElementById(ObjectName).className="form-input-req"
		}
		else if(!CheckAlpha(valFirstName)){
			document.getElementById('dvFirstName').style.display = '';
			document.getElementById("txtFirstName").className="form-input-req"
			document.getElementById("dvFirstName").innerHTML="Please enter only alpha characters (Aa-Zz)!";
		}
		else{
			document.getElementById(DivId).style.display = 'none';
			document.getElementById(ObjectName).className="form-input"
		}
		 
	 }
	 if(Validate=='LastName')
	 {
		 var valLastName=document.getElementById(ObjectName).value;
		 if(value == ""){
			document.getElementById(DivId).style.display = '';
			document.getElementById(ObjectName).className="form-input-req"
		}
		else if(!CheckAlpha(valLastName)){
			document.getElementById('dvLastName').style.display = '';
			document.getElementById("txtLastName").className="form-input-req"
			document.getElementById("dvLastName").innerHTML="Please enter only alpha characters (Aa-Zz)!";
		}
		else{
			document.getElementById(DivId).style.display = 'none';
			document.getElementById(ObjectName).className="form-input"
		}
		 
	 }
	 if(Validate=='Gender')
	 {
		  if(value == ""){
			document.getElementById(DivId).style.display = '';
			document.getElementById(ObjectName).className="";
		}
		else{
			document.getElementById(DivId).style.display = 'none';
			document.getElementById(ObjectName).className="";
			
		}
		 
	 }
	 if(Validate=='PostalCode')
	 {
		  if(value == ""){
			document.getElementById(DivId).style.display = '';
			document.getElementById(ObjectName).className="form-input-req"
			document.getElementById(DivId).innerHTML="Please enter Zip/Postal code. This is your RESET password code !";
		}
		else if((value.length < 5) ||(value.length > 10)){
			document.getElementById(DivId).style.display = '';
			document.getElementById(ObjectName).className="form-input-req";
			document.getElementById(DivId).innerHTML="Zip/Postal code should be 5 to 10 characters in length !";
		}
		else if(!isValidZip(value)){
			document.getElementById(DivId).style.display = '';
			document.getElementById(ObjectName).className="form-input-req";
			document.getElementById(DivId).innerHTML="Zip/Postal Code accept only positive numeric values, characters,<br/>space, + & - !";
		}
		else{
			document.getElementById(DivId).style.display = 'none';
			document.getElementById(ObjectName).className="form-input";
				
		}
		 
	 }
	if(Validate=='confirmemail')
	 {
		if(value == ""){
			document.getElementById(DivId).style.display = '';
			document.getElementById(ObjectName).className="form-input-req"
			document.getElementById(DivId).innerHTML = 'Please enter a confirm email address !';
		 }
		 else if(!isValidEmail(value))
		 {
			document.getElementById(DivId).style.display = '';
			document.getElementById(ObjectName).className="form-input-req"
			document.getElementById(DivId).innerHTML = 'Please use proper email format (e.g. josh@xyz.com)!';
		 }
		 else if(trim(value) != trim(document.getElementById('txtEmail').value))
		 {
			document.getElementById(DivId).style.display = '';
			document.getElementById(ObjectName).className="form-input-req"
			if(document.getElementById(ObjectName).value == ""){
				document.getElementById(DivId).innerHTML= 'Please enter a confirm email address !';
			}
			else{
				document.getElementById(DivId).innerHTML = 'Email and confirm email should be same !';
			}
		 }
		 
	 }
	if(Validate=='password')
	 {
		 	flagCheckNum=0;
			flagCheckAlpha=0;
			for (i = 0; i < value.length; i++){
			  var alphaa = value.charAt(i);
			  var hh = alphaa.charCodeAt(0);
			  if((hh > 47 && hh<58)){
					 flagCheckNum++;
			  }
			  if((hh > 64 && hh<91) || (hh > 96 && hh<123)){
				   flagCheckAlpha++;
			  }
			}
			if(value == ""){
			document.getElementById(DivId).style.display = '';
			document.getElementById(ObjectName).className="form-input-req"
			document.getElementById(DivId).innerHTML = 'Please enter password !';
			}
	}
	if(Validate=='confirmpassword')
	 {
		 flagCheckNum=0;
			flagCheckAlpha=0;
			for (i = 0; i < value.length; i++){
			  var alphaa = value.charAt(i);
			  var hh = alphaa.charCodeAt(0);
			  if((hh > 47 && hh<58)){
					 flagCheckNum++;
			  }
			  if((hh > 64 && hh<91) || (hh > 96 && hh<123)){
				   flagCheckAlpha++;
			  }
			}
		if(value == ""){
			document.getElementById(DivId).style.display = '';
			document.getElementById(ObjectName).className="form-input-req"
			document.getElementById(DivId).innerHTML = 'Please enter confirm password !';
		}
		 else if(trim(value) != trim(document.getElementById('txtPassword').value))
		 {
			document.getElementById(DivId).style.display = '';
			document.getElementById(ObjectName).className="form-input-req"
			if(	document.getElementById(ObjectName).value ==""){
				document.getElementById(DivId).innerHTML = 'Please enter confirm password !';
			}
			else{
				document.getElementById(DivId).innerHTML = 'Password and confirm password should be same !';
			}
		 }
		 
	 }

}
function ChangeBorderColor(f,name)
{
	
        for(var i=0;i<f.length;i++)
        {
                if(f.elements[i].name==name)
                {
					f.elements[i].style.borderColor='#56B5D3';
                }
                else
                {
					f.elements[i].style.borderColor='';                
                }
        }
}
var LocationDivId = '';
function FetchLocationCombo(DivId,LocationId,locationtype,classUsed)
{
	if(locationtype=="country")
	{
	   document.getElementById("cmbStateId").value="";
	   document.getElementById("cmbCityId").value="";
	}
	else if(locationtype=="state")
	{
		document.getElementById("cmbCityId").value="";

	}
	LocationDivId = DivId;
	document.getElementById('transLoading').style.display='';
	myRand=parseInt(Math.random()*99999999);
	strURL = WWWROOT+"/post/PostDisplayLocation.php?LocationId="+LocationId+"&locationtype="+locationtype+"&class="+classUsed;
	Ajax.Request(strURL,AfterFetchLocationCombo);

}//sendRequest
function AfterFetchLocationCombo()
{
	Ajax.setShowMessage(1);
	Ajax.setMessage("Fetching..");
	if(Ajax.CheckReadyState(Ajax.request))
	{
		document.getElementById(LocationDivId).innerHTML = Ajax.request.responseText;	
		document.getElementById('transLoading').style.display='none';

	}
}
function checkText(objIn,id,bln)
{
	if(id == "verification"){
		if(bln){
				if(objIn.value == "please enter verification code"){
					objIn.value = "";
				}
		}
		else{
			if(objIn.value == "please enter verification code" ||objIn.value == ""  ){
					objIn.value = "please enter verification code";
				}
		}
	}
}
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;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_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];}
}
