// Common javascript file
function js_validate_login(username,password)
{
    if(document.getElementById('errorDivHeadLogin'))document.getElementById('errorDivHeadLogin').style.display='none';

    /*if(username.value!="" && password.value=="")
	    {
         alert("Please enter password");
         password.focus();
         return false;
		}
    if(username.value=="" && password.value!="")
	    {
         alert("Please enter usename");
         username.focus();
         return false;
		}
    if(username.value=="" || password.value=="")
	    {
         alert("Please enter usename and password");
         username.focus();
         return false;
		}

	if(!js_checkproper_string(username.value))
       {
         alert("Please enter proper value for username."); 
		 username.value="";
         username.focus();
         return false;
	   }
	if(!js_checkproper_string(password.value))
	   {
         alert("Please enter proper value for password."); 
		 password.value="";
         password.focus();
         return false;
	   }
	if(js_check_whitespace(username.value))
	   {
         alert("Please enter proper value for username.");
		 username.value="";
         username.focus();
         return false;
	   }
	if(js_check_whitespace(password.value))
	   {
         alert("Please enter proper value for password."); 
		  password.value="";
         password.focus();
         return false;
	   }
	   */
	return true;

}




/**
 *Function- js_check_email
 *Validates emailID.
 *@param string emailId enetered in the email ID field
 *@return bool
*/
function js_check_email(email)
{
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if(reg.test(email) == false) {
        return false;
    }
	return true;
}

function js_validate_savemyseach()
{
	if(document.getElementById('textfield_email').value == "" )
	{
		alert ("Email field is mandatory!");
        document.getElementById('textfield_email').focus();
		return false;
	}
	if (!js_check_email(document.getElementById('textfield_email').value))
	{
		alert ("Please enter valid email address.");
        document.getElementById('textfield_email').focus();
		return false;
	}
	return true;
}
function js_check_zipcode(str)
{
	var re = new RegExp("^((\\d{5}-\\d{4})|(\\d{5})|([AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]\\d[A-Za-z]\\s?\\d[A-Za-z]\\d))$");
	//alert(re.test(str));
	return re.test(str);
}
function js_check_password_strong(pswd) {

	
	var space  = " ";
	var pswdLength = pswd.length; 

	if(pswd=="") 
	{
		return false;
	} 
	else          
	{
		//It must not contain a space
		if (pswd.indexOf(space) > -1) {
			return false;
		 }     
	
		//It must contain at least one upper case character     
		if (!(pswd.match(/[A-Z]/))) {
			return false;
		}
		//It must contain at least one lower case character
		      if (!(pswd.match(/[a-z]/))) {
		        return false;
		                                  }
		//It must be at least 5 characters long.
		 if (!(pswdLength <13) || !(pswdLength >= 5))    
		{
		    return false;
		}
	}
	return true;
     	
}
function js_delete_confirmation(strUrl)
{
	var answer = confirm("Are you sure you want to delete?");
    if(answer)
    {
        location.href = strUrl;	
    }
}
function js_check_integer(strValue)
{
	/*var i;
	strValue = strValue.toString();
	for (i = 0; i < strValue.length; i++)
	{
		var c = strValue.charAt(i);
		if (isNaN(c)) 
		{
			return false;
		}
	}
	return true;*/
	var ValidChars = "-0123456789.";
	var IsNumber=true;
	var Char;
	sText=strValue;
 
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	      { 
		      Char = sText.charAt(i); 
		      if (ValidChars.indexOf(Char) == -1) 
		         {
			         IsNumber = false;
		         }
	      }
	return IsNumber;
}
	

function js_check_float(strString) {

 var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
if(blnResult){
    return !isNaN(strString) && isNaN(strString+".1");
}else return false;
}

function js_compare_dates(value1, value2) {
    if(value1!="" && value2!="")
    {
            var date1, date2;
            var month1, month2;
            var year1, year2;

            month1 = value1.substring (0, value1.indexOf ("/"));
            date1 = value1.substring (value1.indexOf ("/")+1, value1.lastIndexOf ("/"));
            year1 = value1.substring (value1.lastIndexOf ("/")+1, value1.length);

            month2 = value2.substring (0, value2.indexOf ("/"));
            date2 = value2.substring (value2.indexOf ("/")+1, value2.lastIndexOf ("/"));
            year2 = value2.substring (value2.lastIndexOf ("/")+1, value2.length);

            if (year1 > year2) return 1;
            else if (year1 < year2) return -1;
            else if (month1 > month2) return 1;
            else if (month1 < month2) return -1;
            else if (date1 > date2) return 1;
            else if (date1 < date2) return -1;
            else return 0;
     }
} 

/**
 *Function- js_validate_forgotPasswordEmail
 *This function is being called from forgotpassword.tpl. It checkes is the username field blank? Also, It internally calls the js_check_email function (passes email enetered as argument) to validate the email ID.
 *@param none
 *@return bool
 */

function js_validate_forgotPwdUnameEmail()
{
	if (document.getElementById('textfield_email').value != "" && document.getElementById('textfield_username').value != "")	
	{
		alert("Please do not enter value in both the fields. Enter value in only one of the fields.");
		document.getElementById('textfield_email').value ="";
		document.getElementById('textfield_username').value = "";
		return false;
	}

	if (document.getElementById('textfield_email').value == "")
	{
		if ((document.getElementById('textfield_username').value) == "" )
		{
			alert("Please enter your username.");
            document.getElementById('textfield_username').focus();
			return false;
		}
	}
	if (document.getElementById('textfield_email').value != "")
	{	
		if(!js_check_email(document.getElementById('textfield_email').value))
		{
			alert("Please enter valid email address.");
            document.getElementById('textfield_email').focus();
			return false;
		}
	}
	return true;
}

function isDate(dateStr) {

    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{2})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?

    if (matchArray == null) {
        return false;
    }

    month = matchArray[1]; // p@rse date into variables
    day = matchArray[3];
    year = matchArray[5];

    if (month < 1 || month > 12) { // check month range
    return false;
    }

    if (day < 1 || day > 31) {
    return false;
    }

    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
    return false;
    }

    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) {
        return false;
        }
    }
    return true; // date is valid
}

//Begin::Changed code for bug-577
function js_showhide_itinerary(id){
	
		 document.getElementById('itinerary').innerHTML="";
		obj = document.getElementById(id);
		if (obj.style.display == "none")
		{
			obj.style.display = "";
			
		} 
		else 
		{
			
			obj.style.display = "none";
			
		}
		//Changes made for bug number 577
		document.getElementById('text_friendname').value="";
		document.getElementById('textfield_email').value="";
}

function js_showhide(id){
	if (document.getElementById)
	{
		obj = document.getElementById(id);
		
		if (obj.style.display == "none")
		{
			obj.style.display = "";
		} 
		else 
		{
			obj.style.display = "none";
		}
	}
}


function js_showhide_sendReceipt(id){
	
		document.getElementById('divsendemail').innerHTML= "";
		obj = document.getElementById(id);
		if (obj.style.display == "none")
		{
			obj.style.display = "";
			
		} 
		else 
		{
			
			obj.style.display = "none";
			
		}	
}
//end::-by mrunal.

function js_validate_senditinerary()
{
	if(document.getElementById('textfield_email').value == "" )
	{
		alert ("Email field is mandatory!");
		return false;
	}
	if (!js_check_email(document.getElementById('textfield_email').value))
	{
		alert ("Please enter valid email address.");
		return false;
	}
	if (document.getElementById('text_friendname').value == "")
	{
		alert ("Please enter friend's name.");
		return false;
	}
	return true;
}
function IsNumeric(strString)
{
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
            blnResult = false;
         }
      }
   return blnResult;
}

function IsResDepositeNumeric(strString)
{
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
            blnResult = false;
         }
      }
   return blnResult;
}

function isPrice(numStr){
	if(!IsNumeric(numStr)) return false;

    var arrnum=numStr.split('.');
    if(arrnum.length >2) return false;

	if(eval(numStr)==0)return false;

    var matches = numStr.match(/\$?[1-9]{0}[0-9]{0,3}(\.[0-9]{1,2})?/g);
   
    for(var i in matches){
        if(matches[i] == numStr){
            return true;
        }
    }
    return false;
} 

   // check for valid phone number
  function IsValidPhone(strString)
 {
   
   //var strValidChars = "0123456789-() ";
   var strValidChars = "0123456789-() /#ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
   var strChar;
   //var blnResult = true;

   if (strString.length == 0) return false;
	// && blnResult == true
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length; i++)
      {
      strChar = strString.charAt(i);
	  
      if (strValidChars.indexOf(strChar) == -1)
         {
         	return false;
         }
      }
   return true;
  }

function js_change_text(id,strText)
{  
   if(strText == "")
   {
       document.getElementById(id).value = "";
   }
   var str1 = strText.toString();
   var str2 = document.getElementById(id).value; 
   if(navigator.appName!="Netscape")
   {	 
	   str1 = str1.replace(new RegExp(/\n/ig),"");
	   str2 = str2.replace(new RegExp(/\r\n/g),"");
   }
   if(str1 == str2){
		document.getElementById(id).value="";
   } 
}

function js_get_cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function js_get_username(){
    if( document.getElementById('username').value=="Username"){
        document.getElementById('username').value="";
    }
}
//code changed by mrunal:Bug no.655
function openwindow(url,properties)
{
	var posX, posY; 
	var w=700, h=450; 
	var offsetX=50, offsetY=50; //x and y offset relative to the parent window
	if (typeof window.screenLeft != "undefined"){ //IE
		posX = window.screenLeft + offsetX;
		posY = window.screenTop + offsetY;
	}
	else if (typeof window.screenX != "undefined"){ //NS/Moz

		posX = window.screenX + offsetX;
		posY = window.screenY + offsetY;
	}
	else { //default - center of screen
		posX = screen.availWidth/2 - w/2;
		posY = screen.availHeight/2 - h/2;
	}
	var win = window.open(url,'',"width="+w+",height="+h+",left="+posX+",top="+posY+",scrollbars=1");
	win.focus();
}



function js_checkproper_string(string)
{
	for(var i=0;i<string.length;i++)
	{  
		if(string.charCodeAt(i)>126 && string.charCodeAt(i)!=10  && string.charCodeAt(i)!=13 )
		{

		    return false;
		}
	
		if(string.charCodeAt(i)<31 && string.charCodeAt(i)!=10  && string.charCodeAt(i)!=13)
		{

		return false;
		}
	}
	
	return true;
} 

function js_check_whitespace(s)

{   
	var reWhitespace = /^\s+$/;
    return (isEmpty(s) || reWhitespace.test(s));
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
function js_generate_receipt(strUrl)
{
	newwindow = window.open(strUrl,'generatemap','height=700,width=720,titlebar=0,toolbar=0,scrollbars=1,location=0,directories=0,statusbar=0,menubar=0,resizable=1');
	if (window.focus) {newwindow.focus()}
}

function js_showhide_div(image,val,path,id)
{
	if(document.getElementById(val+id).style.display=='none')
	{
		document.getElementById(val+id).style.display='block';
		document.getElementById(image+id).src=path+"images/buttons/minus.gif";
		document.getElementById(image+id).title="Collapse";
	}
	else
	{
		document.getElementById(val+id).style.display='none';
		document.getElementById(image+id).src=path+"images/buttons/plus.gif";
		document.getElementById(image+id).title="Expand";
	}
}

function CreateExcelSheet()
{
	var myTable = document.getElementById('gTable');
	var x=myTable.rows
	var xls = new ActiveXObject("Excel.Application");
	xls.visible = true
	xls.Workbooks.Add
	for (i = 0; i < x.length; i++)
	{
		var y = x[i].cells

		for (j = 0; j < y.length; j++)
		{
			xls.Cells( i+1, j+1).Value = y[j].innerText
		}
	}

}
function js_check_alphastring(string)
{
	
	for(var j=0; j<string.length; j++)
	 {
		  var alpha = string.charAt(j);
		  var hh = alpha.charCodeAt(0);
		  if((hh >64 && hh<91) || (hh > 96 && hh<123) || hh==32 ||hh==39 || hh==40 || hh==41 || hh==46)
		  {
		     
		  }	
		  else
		  {
			 return false;
		  }
		}
 return true;
}


function js_check_alphanumeric(string)
{

	for(var j=0; j<string.length; j++)
	 {
		  var alpha = string.charAt(j);
		  var hh = alpha.charCodeAt(0);
          
		  if((hh >47 && hh<58) ||(hh >64 && hh<91) || (hh > 96 && hh<123) || hh==32 ||hh==39)
		  {
		    
		  }
		  else
		  {  
			 return false;
		  }
	}
 return true;
}

function js_check_fnamelname(string)
{

	//Fix for bug no - 1058 - Abhijeet
	if(js_check_integer(string) || !js_checkproper_string(string))
	{
		return false;
	}
	/*
	for(var j=0; j<string.length; j++)
	 {
		  var alpha = string.charAt(j);
		  var hh = alpha.charCodeAt(0);
		  
		  
		  if((hh>64 && hh<91) || (hh>96 && hh<123) || hh==32 || hh==39)
		  {
		    
		  }
		  else
		  {
			return false;
		  }
		  
		}
  */
 return true;
}


function js_check_company(string)
{
	
	for(var j=0; j<string.length; j++)
	 {
		  var alpha = string.charAt(j);
		  var hh = alpha.charCodeAt(0);
          
		  if((hh>=47 && hh<58) ||(hh>64 && hh<91) || (hh>96 && hh<123) || hh==32 || hh==38 || hh==39 || hh==45 || hh==46)
		  {
		    
		  }
		  else
		  {
			 return false;
		  }
		}
 return true;
}


function js_check_textarea(string)
{
	
	for(var j=0; j<string.length; j++)
	 {
		  var alpha = string.charAt(j);
		  var hh = alpha.charCodeAt(0);
		  
		  if((hh >=32 && hh<126) || (alpha=="\t") || (alpha=="\n") || (alpha=="\r"))
		  {
		    
		  }
		  else
		  {
			 return false;
		  }
		}
 return true;
}


function isContainSpacesOrTab(val)
{
      if(val==null){return false;}
      if(val.length==0) {return false;}
      for(var i=0;i<val.length;i++) 
	  {

            if ((val.charAt(i)==" ") || (val.charAt(i)=="\t")) {return true;}
      }
      return false;     
 }



function js_validDate_searchbox(dateStr) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
// To require a 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Date is not in a valid format MM/DD/YY.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
}
}
return true;  // date is valid
}

function js_change_class(Elem, myClass) {
	
	Elem.className = myClass;
}


// javascript file

function js_show_usernamediv(strDivId, labelUserEmail, anchorCancel, changelabel, label)
{
	var strShowHideDiv= document.getElementById(strDivId);
	var strShowHideLabel = document.getElementById(labelUserEmail);
	var strAnchorCancel = document.getElementById(anchorCancel);
	var strChangeLabel = document.getElementById(changelabel);
	strShowHideDiv.style.display = 'block';
	strShowHideLabel.style.display = 'none';
	strAnchorCancel.style.visibility = 'visible';
	strChangeLabel.innerHTML = label;
}
function js_show_passdiv(strDivId, labelUserEmail, anchorCancel, changelabel, label)
{
	var strShowHideDiv= document.getElementById(strDivId);
	var strShowHideLabel = document.getElementById(labelUserEmail);
	var strAnchorCancel = document.getElementById(anchorCancel);
	var strChangeLabel = document.getElementById(changelabel);
	strShowHideDiv.style.display = 'block';
	strShowHideLabel.style.display = 'none';
	strAnchorCancel.style.visibility = 'visible';
	strChangeLabel.innerHTML = label;
}
function js_hide_passdiv(strDivId, labelUserEmail, anchorCancel, changelabel, firstfield, secondfield, label)
{
	var strShowHideDiv= document.getElementById(strDivId);
	var strShowHideLabel = document.getElementById(labelUserEmail);
	var strAnchorCancel = document.getElementById(anchorCancel);
	var strChangeLabel = document.getElementById(changelabel);
	document.getElementById(firstfield).value = "";
	document.getElementById(secondfield).value = "";
	strShowHideDiv.style.display = 'none';
	strShowHideLabel.style.display = 'block';
	strAnchorCancel.style.visibility = 'hidden';
	strChangeLabel.innerHTML = label;
}
function js_hide_usernamediv(strDivId, labelUserEmail, anchorCancel, changelabel, firstfield, label)
{
	var strShowHideDiv= document.getElementById(strDivId);
	var strShowHideLabel = document.getElementById(labelUserEmail);
	var strAnchorCancel = document.getElementById(anchorCancel);
	var strChangeLabel = document.getElementById(changelabel);
	document.getElementById(firstfield).value = "";
	strShowHideDiv.style.display = 'none';
	strShowHideLabel.style.display = 'block';
	strAnchorCancel.style.visibility = 'hidden';
	strChangeLabel.innerHTML = label;
}

function js_set_defaultvalues(node) {
			tag = node.tagName;
			if (tag && !node.getAttribute("disabled")) {
				var valid = 0;
				switch (tag) {
					case "DIV":
						if (node.id == "upload") {
							node.innerHTML = node.innerHTML;
						}
						break;
					case "INPUT":
						if(node.type!=="button" && node.type!=="submit")
						node.value ="";
						valid = 1;
						break;
					case "SELECT":
						var opt = node.options;
						for (a = 0; a < opt.length; a++) {
							if (opt[a].defaultSelected) {
								node.selectedIndex = 0;
							}
						}
						valid = 1;
						break;
				}
				foo = node.getAttributeNode('onchange');
				if (valid) {
					js_set_childrenvalues ( node.name, node.value );
				}
			}
		}
		
		function js_reser_values(section)
		{
			var s = document.getElementById (section);
			var nodes1 = s.getElementsByTagName("DIV");
			var nodes2 = s.getElementsByTagName("INPUT");
			var nodes3 = s.getElementsByTagName("SELECT");
			for (var i = 0; i < nodes1.length; i++) js_set_defaultvalues(nodes1[i]);
			for (var i = 0; i < nodes2.length; i++) js_set_defaultvalues(nodes2[i]);
			for (var i = 0; i < nodes3.length; i++) js_set_defaultvalues(nodes3[i]);
		}
		
		function js_check_hexvalues(str)
		{
		var re =/[^0-9a-f]/i;
		return re.test(str);
		}
		
		function js_set_childrenvalues(name, value) {
			var all_els = document.getElementsByTagName("INPUT");
			for (var i = 0; i < all_els.length; i++) {
				if (all_els[i].name == name) {
					all_els[i].value = value;
				}
			}
		}

/**
*
*Validates the url (Being used on affiliate register and editprofile)
*
*/
//Bug no 844
/*function isURL(value) {
    
	//var regexp = /(ftp:|http:|https:)\/\/((\w+:{0,1}\w*@)?)(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
    var regexp = /(ftp:|http:|https:)\/\/(www.)?[A-Za-z0-9\.-]{3,}\.[A-Za-z]{1,}/;
	if (!regexp.test(value)) {
        return false;
    }
	return true;
}*/

function js_validate_font(string)
{
	for(var j=0; j<string.length; j++)
	 {
		  var alpha = string.charAt(j);
		  var hh = alpha.charCodeAt(0);
		  
		  if((hh >64 && hh<91) || (hh > 96 && hh<123) || hh==32)
		  {
		     
		  }
		  else if(hh==44)
		  {
		  	 return true;
		  }
		  else
		  {
			 return false;
		  }
		}
 return true;
}

function js_display_downloadtab(id1,id2,id3,id4)
{
    document.getElementById(id1).style.display="block";
    document.getElementById(id2).style.display="none";
    document.getElementById(id3).className="current";
    document.getElementById(id4).className="";
}

function js_show_preview(url,id,actionurl,funcname)
{
	   if(funcname)
	    {
			document.getElementById(id).target = "popup";				
			window.open('','popup','height=550,width=600,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no');
			document.getElementById(id).action=url;
			document.getElementById(id).submit ();
			document.getElementById(id).target ="";
			document.getElementById(id).action=actionurl;
		}
}


/**
* Populates states as per the country selected in ddl.
*
*/


function js_fetch_states(id,url)
{
	if(id == 0)
	{
		document.getElementById('select_state').options.length=0;
		var optn = document.createElement("OPTION");
		optn.text ="Select State";
		optn.value = 0;
		document.getElementById('select_state').options.add(optn);	
	}
	else
	{
		ajax.setVar("id",id);
		ajax.requestFile = url;
		ajax.method = "post";
		ajax.onCompletion =js_show_statedata;
		ajax.runAJAX();
	}
	
}
function js_show_statedata()
{
	var response = ajax.response.split(",");
	document.getElementById('select_state').options.length=0;
	for(var i=0;i<response.length;i++)
	{
		    var value =response[i].split(":");
			var optn = document.createElement("OPTION");
			optn.text = value[1];
			optn.value = value[0];
			document.getElementById('select_state').options.add(optn);	
	}
}

function js_proper_date(date)
{

if(date !="")
    {
        var arrdate=date.split("/");
        if(arrdate[0].length<2)
        {
        arrdate[0]=0+arrdate[0];
        }
        if(arrdate[1].length<2)
        {
        arrdate[1]=0+arrdate[1];
        }
        if(arrdate[2].length<2)
        {
        arrdate[2]=0+arrdate[2];
        }
        return arrdate[0]+"/"+arrdate[1]+"/"+arrdate[2];
    }
}


/**
* Function would limit entries to 255 characters.
* Where m = 250 and l = textarea object
*/
/*function getLength(l,m)
{
	window.status = l + " of " + m + " maximum characters.";
	alert(l<m);
	return (l<m);
	
}*/
function maxLength(t,m)
{
	var l = t.value.length;
	
	if (l > m)
	{
		alert("Your entry of " + l
		+ " characters exceeds the maximum allowable limit of " + m + ".\n\n"
		+ "It will now be truncated.");
		t.value = t.value.substring(0,m);
		
	}	
	return l<m;
	
}
function maxLengthForAnswer(t,m)
{
	var l = t.value.length;
	if (l > m)
	{
		alert("Your entry of " + l
		+ " characters exceeds the maximum allowable limit of " + m-1 + ".\n\n");
		//t.value = t.value.substring(0,m);
		
	}	
	return l<m;
	
}


function js_submit_form(id,url,val)
{
	document.getElementById(id).action=url;
	document.getElementById(id).submit();
}

function js_get_selectedzip(url,form)
{
document.getElementById('formlink').href=url+form.value+".zip";

}
function stripslashes(str) {
    str=str.replace(/\\'/g,'\'');
    str=str.replace(/\\"/g,'"');
    str=str.replace(/\\0/g,'\0');
    str=str.replace(/\\\\/g,'\\');
    return str;
}
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function js_send_sms(url)
{
	   
		ajax.requestFile = url;
        ajax.method = "post";
        ajax.onCompletion =js_sms_sent;
        ajax.runAJAX();
}
//Don't delete the function
function js_sms_sent()
{
	alert("Message sent successfully");
}

function js_activate(url)
{
    location.href =url;
}

function increaseFlashCounter()
{
        
		
		ajax.requestFile = document.getElementById('counterurl').value;
		ajax.method = "post";
		ajax.onCompletion =js_increment_count;
		ajax.runAJAX();
		
}
function js_increment_count()
{
	
}

function ISVT_onInviteOffered() {
    //code for invite offer case	
	var strUrl = document.getElementById('hid_II_Offered').value;
	var tmpIm = new Image();
	tmpIm.src = strUrl;
}
function ISVT_onInviteAccepted() {
    //code for invite accepted case
	var strUrl = document.getElementById('hid_II_Accepted').value;
	var tmpIm = new Image();
	tmpIm.src = strUrl;
}

function ISVT_onInviteDeclined() {
    //code for invite declined case       
	var strUrl = document.getElementById('hid_II_Declined').value;
	var tmpIm = new Image();
	tmpIm.src = strUrl;
}
// can be used for testing ....
//function testISVT(){
//	ISVT_onInviteOffered();
//	ISVT_onInviteAccepted();
//	ISVT_onInviteDeclined();
//	return false;
//}

/*function js_barcode(str)
{
	//var barcodereg = /[0-9A-Z-\.\$\s\/+%]/g;
	var barcodereg = /[A-Z0-9 \.$+%-\/]/g;
	return barcodereg.test(str);
}*/

function wordwrap( str, width, brk, cut ) {
 
    brk = brk || '\n';
    width = width || 75;
    cut = cut || false;
 
    if (!str) { return str; }
 
    var regex = '.{1,' +width+ '}(\\s|$)' + (cut ? '|.{' +width+ '}|.+$' : '|\\S+?(\\s|$)');
 
    return str.match( RegExp(regex, 'g') ).join( brk );
 
}

/*
checks/uncheck all the checkboxes in form
*/
function js_checkbox_checkuncheck_all(strCheckAllid, checkboxid, checkboxcount)
{
	if(document.getElementById(strCheckAllid).checked)
	{
		check = true;	
	}
	else
	{
		check = false;
	}

	for(i=0;i<=checkboxcount;i++)
	{
		itemCheck = checkboxid+i;
		if(document.getElementById(itemCheck)!=undefined) 
		{
			document.getElementById(itemCheck).checked = check; 
		}
	}
	
}

function js_validate_terms()
{
	if(document.getElementById('checkbox_terms') && document.getElementById('checkbox_terms').checked!=true)
	{
		alert("Please check agree to terms and service checkbox.");
		document.getElementById('checkbox_terms').focus();
		return false;
	}
	return true;
}


function js_check_passwrd(pswd) {

	var space  = " ";
	var pswdLength = pswd.length; 

	if(pswd=="") {
		return false;
	              } 
	else          {
		//It must not contain a space
		     if (pswd.indexOf(space) > -1) {
		         return false;
		                                   }
	
		//It must contain at least one upper case character     
//		      if (!(pswd.match(/[A-Z]/))) {
//		         return false;
//		                                  }
		//It must contain at least one lower case character
//		      if (!(pswd.match(/[a-z]/))) {
//		        return false;
//		                                  }
		//It must be at least 5 characters long.
		      if (!(pswdLength >= 5))    {
		        return false;
		                                 }
		      if(!js_checkproper_string(pswd))
		                                 {
		        return false;
		                                 }
	               }

	
     return true;
     	
     }

