// JavaScript Document
function PhoneNumber_Validation(field)
{
	dom = document.getElementById(field);
	//var mikExp = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|]/;
	var mikExp = /[a-z,A-Z]/;
	var strPass = dom.value;
	var strLength = strPass.length;
	var lchar = dom.value.charAt((strLength) - 1);
	if(lchar.search(mikExp) != -1) 
	{
		alert("No Characters allowed.");
	 	var tst = dom.value.substring(0, (strLength) - 1);
		dom.value = tst;
	}
}
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}
function LTrim(str)
{
        var whitespace = new String(" \t\n\r ");
        // last space character is not a space, but alt+0160,
        // another invisible char.
        var s = new String(str);
        if (whitespace.indexOf(s.charAt(0)) != -1) {
            // We have a string with leading blank(s)...
            var j=0, i = s.length;
            // Iterate from the far left of string until we
            // don't have any more whitespace...
            while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                j++;
            // Get the substring from the first non-whitespace
            // character to the end of the string...
            s = s.substring(j, i);
        }
        return s;
}
// Trims all spaces to the right of a specific string
function RTrim(str)
{
        // We don't want to trip JUST spaces, but also tabs,
        // line feeds, etc.  Add anything else you want to
        // "trim" here in whitespace
        var whitespace = new String(" \t\n\r ");
        // last space character is not a space, but alt+0160,
        // another invisible char.
        var s = new String(str);
        if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
            // We have a string with trailing blank(s)...
            var i = s.length - 1;       // Get length of string
            // Iterate from the far right of string until we
            // don't have any more whitespace...
            while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                i--;
            // Get the substring from the front of the string to
            // where the last non-whitespace character is...
            s = s.substring(0, i+1);
        }
        return s;
}
// Trims all spaces to the left and right of a specific string by calling RTim
// and LTrim
function Trim(str)
{
        return RTrim(LTrim(str));
}
function isInteger(s)
{
   var i;
   if (isEmpty(s))
   if (isInteger.arguments.length == 1) return 0;
   else return (isInteger.arguments[1] == true);

   for (i = 0; i < s.length; i++)
   {
       var c = s.charAt(i);
       if (!isDigit(c)) return false;
   }
   return true;
}
function isEmpty(s)
{
      return ((s == null) || (s.length == 0))
}
function isDigit (c)
{
      return ((c >= "0") && (c <= "9"))
}
function isEmail(str)
{ 
		var reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
		if(reg.exec(str))
			return true;
		else
			return false;
}
//phone Number Validation
function isValidPhoneNumber(phoneNumber)
{
	var patt1=/[^0-9()-/\.]/g;
	var Invalid_char = phoneNumber.match(patt1);
	if(Invalid_char == null)
		return true;
	else
		return false;
}
function NameChecking(checkString) 
{
	var tempString="";
    var regExp = /^[A-Za-z '"]$/;
    if(checkString != null && checkString != "")
    {
    	for(var i = 0; i < checkString.length; i++)
        { 
        	if (!checkString.charAt(i).match(regExp))
            {
            	return false;
            }
        }
    }
    else
    {
          return false;
    }
    return true;
}

function NameChecking2(checkString) 
{
	var tempString="";
    var regExp = /^[A-Za-z \/\ , .'"]$/;
    if(checkString != null && checkString != "")
    {
    	for(var i = 0; i < checkString.length; i++)
        { 
        	if (!checkString.charAt(i).match(regExp))
            {
            	return false;
            }
        }
    }
    else
    {
          return false;
    }
    return true;
}
function createRequest()
{
	try
	{		
		request = new XMLHttpRequest();
	}
	catch(trymicrosoft)
	{
		try
		{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(othermicrosoft)
		{
			try
			{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(failed)
			{
				request = null;
			}
		}
	}
	if(request == null)
	{
		alert("Error creating request object");
	}
}
function Validate_BackgroundCheck()
{
	var str ="";
	str = Is_NULL(Trim($JQ_Obj('#fname_txt').val()),"First Name");
	str += Is_NULL(Trim($JQ_Obj('#lname_txt').val()),"Last Name");
	str += Is_NULL($JQ_Obj('#country_ls').val(),"Country Name");
	str += Is_NULL($JQ_Obj('#state_ls').val(),"State Name");
	str += Is_NULL(Trim($JQ_Obj('#street_txt').val()),"Street Name");
	str += Is_NULL(Trim($JQ_Obj('#city_txt').val()),"City Name");
	str += Is_NULL(Trim($JQ_Obj('#zip_txt').val()),"Zip Code");
	str += Is_NULL(Trim($JQ_Obj('#date_txt').val()),"Date");
	str += Is_NULL(Trim($JQ_Obj('#ssno_txt').val()),"Social Security Number");
	str += Is_NULL(Trim($JQ_Obj('#telephoneno_txt').val()),"DayTime Telephone Number");
	str += Is_NULL(Trim($JQ_Obj('#licenceno_txt').val()),"Driver's License Number");
	str += Is_NULL(Trim($JQ_Obj('#state_issuance_txt').val()),"State of Issuance");
	if($JQ_Obj('#month_ls').val() == "")
		str += Is_NULL($JQ_Obj('#month_ls').val(),"Date of Birth");
	else if($JQ_Obj('#day_ls').val() == "")
		str += Is_NULL($JQ_Obj('#day_ls').val(),"Date of Birth");
	else if($JQ_Obj('#year_ls').val() == "")
		str += Is_NULL($JQ_Obj('#year_ls').val(),"Date of Birth");

	str += Is_NAN(Trim($JQ_Obj('#zip_txt').val()),"Invalid Zip");
	str += Is_NAN(Trim($JQ_Obj('#ssno_txt').val()),"Invalid Social Security Number");
	if(str)	{
		alert("Following Field (s) are Mandatory \n \n"+str);
		return false;
	}	else	{
		return true;
	}
}
function showImageReOrder()
{
	scroll(0,0);
	document.getElementById("lightboxarea").style.display = "block";
	document.getElementById("reorder-gallery").style.display = "block";
}
function closeImageReorder()
{
	scroll(0,0);
	document.getElementById("lightboxarea").style.display = "none";
	document.getElementById("reorder-gallery").style.display = "none";
}
function isValidURL(url)
{
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url))
	{
        return true;
    }
	else
	{
        return false;
    }
} 
// Validate correct date or not
function IsValidDate(Day,Mn,Yr){
    var DateVal = Mn + "/" + Day + "/" + Yr;
    var dt = new Date(DateVal);

    if(dt.getDate()!=Day)
	{
        return(false);
    }
    else if(dt.getMonth()!=Mn-1)
	{
    	//this is for the purpose JavaScript starts the month from 0
        return(false);
    }
    else if(dt.getFullYear()!=Yr)
	{
        return(false);
    }    
    return(true);
}
function DayChangeFunction(month,id)
{
	var Days = new Array(); // Days in a month
	Days['01']="31";
	Days['02']="28";
	Days['03']="31";
	Days['04']="30";
	Days['05']="31";
	Days['06']="30";
	Days['07']="31";
	Days['08']="31";
	Days['09']="30";
	Days['10']="31";
	Days['11']="30";
	Days['12']="31";
	var day_select;
	var dayselectbox_ls = "day_combo"+id;
	var max_day = Days[month];
	var day = document.getElementById("day_combo"+id).value;
	day_select = "<select name='"+dayselectbox_ls+"' id='"+dayselectbox_ls+"' style='width:50px'><option value=''>DD</option>";
	for(i=1;i<=max_day;i++)
	{
		var select_data=(i==day ? "selected":"");
		day_select = day_select+'<option value='+i+' '+select_data+'>'+i+'</option>';
	}
	day_select = day_select+"</select>";
	document.getElementById('span_day_'+id).innerHTML = day_select;
}
function YearChangeFunction(year,field_id)
{
	if(document.getElementById("month_combo"+field_id).value == 02)
	{
		if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
			var max_day = 29;
		else 
			var max_day = 28;
		var day_select;
		var dayselectbox_ls = "day_combo"+field_id;
		var day = document.getElementById("day_combo"+field_id).value;
		day_select = "<select name='"+dayselectbox_ls+"' id='"+dayselectbox_ls+"' style='width:50px'><option value=''>DD</option>";
		for(i=1;i<=max_day;i++)
		{
			var select_data=(i==day ? "selected":"");
			day_select = day_select+'<option value='+i+' '+select_data+'>'+i+'</option>';
		}
		day_select = day_select+"</select>";
		document.getElementById('span_day_'+field_id).innerHTML = day_select;
	}
}
function validateCityName(domVal)
{
	var regExp1 = /[A-Za-z]{3}/;
	var First_Letter_regExp = /^[A-Za-z]{1}/;
	var city_val = document.getElementById(domVal).value;
	if(regExp1.test(city_val))
	{
		if(First_Letter_regExp.test(city_val))
			return true;
		else
			return false
	}
	else
		return false;
}
function validateStateName(domVal)
{
	var regExp1 = /[A-Za-z]{2}/;
	var First_Letter_regExp = /^[A-Za-z]{1}/;
	var state_val = document.getElementById(domVal).value;
	if(regExp1.test(state_val))
	{
		if(First_Letter_regExp.test(state_val))
			return true;
		else
			return false
	}
	else
		return false;
}
//added Anitta 
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars;
	//chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars;
	//chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

