function func_is_combo_selected(obj_combo)
{
	var i_loop;
	if(obj_combo.selectedIndex>0 && obj_combo.options[obj_combo.selectedIndex].value!="")
	{
		return true;
	}
	else
	{
		return false;
	}
}

function func_is_option_selected(obj_radio)
{
	var i_loop;
	for (i_loop=0; i_loop<obj_radio.length; i_loop++)
	{
		if ((obj_radio[i_loop].checked) && (obj_radio[i_loop].value != ""))
		{
			return true;
		}
	}
	return false;
}

function get_selected_radio_option(obj_radio)
{
	var optionValue = "";
	for (var i_loop=0; i_loop<obj_radio.length; i_loop++)
	{
		if (obj_radio[i_loop].checked)
		{
			 optionValue = obj_radio[i_loop].value;
			 return optionValue;
		}
	}
}


function func_is_zip(param_text) 
{ 
	var b_is_zip=true; 
	if(func_trim(param_text)!="") 
	{ 
		var str_text=new String(func_trim(param_text));
		var i_length=func_len(str_text);
		var i_loop; 
		if(i_length <6)
			b_is_zip=false;
		else
		{
			for (i_loop=0; i_loop<i_length; i_loop++) 
			{ 
				if (!((str_text.charCodeAt(i_loop)>=48 && str_text.charCodeAt(i_loop)<=57) || (str_text.charAt(i_loop)=="-") || (str_text.charAt(i_loop)=="(") || (str_text.charAt(i_loop)==")") || (str_text.charCodeAt(i_loop)==32))) 
				{ 
					b_is_zip=false; 
				} 
			}
		}
	} 
	return b_is_zip; 
}

function is_telephone_number(text)
{
	var bflag=true;
	if(text != "")
	{
		var k = func_len(text);
		var i;
		for (i=0; i<k; i++)
		{
			if (!((text.charCodeAt(i) >= 48 && text.charCodeAt(i) <= 57) || (text.charAt(i) == "-")|| (text.charAt(i) == "(")|| (text.charAt(i) == ")") || (text.charAt(i) == "+") || (text.charAt(i) == ".")|| (text.charAt(i) == " ")))
			{
				bflag=false;
			}
		}
	}
	return bflag;
}

function is_valid_email(str) 
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	var b_error = false;
	if (str.indexOf(at)==-1){
	  b_error = true;
	}

	else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   b_error = true;
	}

	else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		b_error = true;
	}

	else if (str.indexOf(at,(lat+1))!=-1){
		b_error = true;
	}

	else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		b_error = true;
	 }

	else if (str.indexOf(dot,(lat+2))==-1){
		b_error = true;
	 }
	
	 if (str.indexOf(" ")!=-1){
		b_error = true;
	 }
	 
	 return b_error;
}

function is_valid_URL(url) 
{
	if( url.match(/^(http|https)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#\=]\w+)*\/?$/i) ) 
	{
		if(url=='http://' || url=='https://') 
		{
			return 1;
		}
	}
	else
	{
		if(url.length>0) return 2;
	}
}

function func_trim(param_text)
{
	var str_text=new String(param_text);
	var str_return_text;
	str_return_text="";
	b_non_blank_started=false;
	b_non_blank_ended=false;
	str_intermediate_blank_chunk="";
	var i_loop;
	for(i_loop=0;i_loop<str_text.length;i_loop++)
	{
		if(str_text.charCodeAt(i_loop)!=32)
		{
			if(!b_non_blank_started)
			{
				b_non_blank_started=true;
			}
			if(b_non_blank_started && !b_non_blank_ended)
			{
				str_return_text+=str_text.charAt(i_loop);
			}
			if(b_non_blank_ended)
			{
				str_return_text+=(str_intermediate_blank_chunk+str_text.charAt(i_loop));
				b_non_blank_ended=false;
				str_intermediate_blank_chunk="";
			}
		}
		else
		{
			if(b_non_blank_started)
			{
				b_non_blank_ended=true;
				str_intermediate_blank_chunk+=" ";
			}
		}
	}
	return str_return_text;
}

function func_len(param_text)
{
	var str_text=new String(func_trim(param_text));
	return str_text.length;
}

function valid_card_number(objName) 
{
	var ccnLength;
	var cPrefix2;
	var nString = "";
	var total = 0;
	var ccNumber = "";
	var i;
	
	//Don't bother checking if the length is 0
	if( objName.value.length == 0 ) return true;
	
	//Strip out all dash and space characters
	for (i = 0; i < objName.value.length; i++) {
		if (objName.value.charCodeAt(i) >= 48 && objName.value.charCodeAt(i) <= 57) {
			ccNumber = ccNumber + objName.value.charAt(i);
		}
		else if (objName.value.charCodeAt(i) != 45 && objName.value.charCodeAt(i) != 32) {
			return false;
			
		}
	}
	
	//Set variable to credit card length
	ccnLength = ccNumber.length;
	
	//Check card number prefix and length
	if (ccnLength >= 13) {
		cPrefix2 = parseInt(ccNumber.charAt(0) + ccNumber.charAt(1));
		cPrefix3 = parseInt(ccNumber.charAt(0) + ccNumber.charAt(1) + ccNumber.charAt(2));
		cPrefix4 = parseInt(ccNumber.charAt(0) + ccNumber.charAt(1) + ccNumber.charAt(2) + ccNumber.charAt(3));
		if (cPrefix2 > 49 && cPrefix2 < 56) { //Mastercard    ***** NOTE: Test mastercards can start with 50, valid cards cannot
			if (ccnLength != 16) {
				return false;
				
			}
		} else if (ccNumber.charAt(0) == "4") {    //VISA
			if (ccnLength != 16 && ccnLength != 13) {
				return false;
				
			}
		} else if (cPrefix2 == 34 || cPrefix2 == 37) { //AMEX
			if (ccnLength != 15) {
				return false;
				
			}
		} /*else if ((cPrefix3 > 299 && cPrefix3 < 306) || cPrefix2 == 36 || cPrefix2 == 38) { //Diners Club/Carte Blanche
			if (ccnLength != 14) {
				return false;
				
			}
		} */else if (cPrefix4 == 6011) {  //Discover
			if (ccnLength != 16) {
				return false;
				
			}
		} /*else if (cPrefix4 > 3527 && cPrefix4 < 3590) {  //JCB
			if (ccnLength != 16) {
				return false;
				
			}
		} else if (ccNumber.charAt(0) == "6") {    //SEARS
			if (ccnLength > 16) {
				return false;
				
			}
		} */else {
			return false;
			
		}
		/*
		if (ccNumber.charAt(0) != "6") { //SEARS
			//Perform MOD check
			for (i=1; i <= ccnLength; i++) {
				if ((i % 2) == 0) {
					nString = nString + (parseInt(ccNumber.charAt(ccnLength - i)) * 2);
				}
				else {
					nString = nString + ccNumber.charAt(ccnLength - i);
				}
			}
			
			for (i=0; i < nString.length; i++) {
				total = total + parseInt(nString.charAt(i));
			}
			
			if (total % 10 != 0) {
				return false;
				
			}
			else {
				return true;
				
			}
		} else {
			//SEARS Card - Do not perform MOD 10 check
			return true;
		}*/

	}
	else {
		return false;
	}

}
function openUrl(url, name, w, h, scroll) {
	



	
	LeftPosition	= (screen.width)?(screen.width-w)/2:100;
	TopPosition		= (screen.height)?(screen.height-h)/2:100;
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
	window.open(url, name, settings);
	
}

function days_in_month(month,year) 
{
	var m = [31,28,31,30,31,30,31,31,30,31,30,31];
	if (month != 2) return m[month - 1];
	if (year%4 != 0) return m[1];
	if (year%100 == 0 && year%400 != 0) return m[1];
	return m[1] + 1;
}

function is_us_zip(s) 
{
     // Check for correct zip code
     reZip = new RegExp(/(^\d{5}-\d{4}$)/);
     if (!reZip.test(s)) {
		 alert("Please enter a valid zip code. The hyphen character should be used with a properly formatted 5 digit+4 zip code, like '12345-6789'.   Please try again.");
         return false;
     }
	return true;
}

function is_us_zip2(field)
{
   var valid = "0123456789-";
   var hyphencount = 0;
	alert(field.length);
   if (field.length!=10)
   {
       alert("Please enter 5 digit+4 zip code.");
       return false;
   }
   for (var i=0; i < field.length; i++)
   {
       temp = "" + field.substring(i, i+1);
       if (temp == "-") hyphencount++;
       if (valid.indexOf(temp) == "-1") {
           alert("Invalid characters in your zip code.  Please try again.");
           return false;
       }
       if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-"))
       {
           alert("Please enter a valid zip code.The hyphen character should be used with a properly formatted 5 digit+4 zip code, like '12345-6789'.   Please try again.");
           return false;
       }
   }
   return true;
}


function openW(mypage,myname,w,h,features) {
	if(screen.width){
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
	}else{winl = 0;wint =0;}
		if (winl < 0) winl = 0;
		if (wint < 0) wint = 0;
		var settings = 'height=' + h + ',';
		settings += 'width=' + w + ',';
		settings += 'top=' + wint + ',';
		settings += 'left=' + winl + ',';
		settings += features;
		win = window.open(mypage,myname,settings);
		win.window.focus();
}

