function checkValidNull(obj, msg)
{
	if(obj)
	{
		if(Trim(obj.value)=="")
		{
		
			alert(msg);	
			//obj.focus();
			return false;
		}
	}
	else
		return false;	
		
	return true;	
}

function Trim(s) 
{
	return s.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
function chkSpace(events)
{
	var unicodes=events.charCode? events.charCode :events.keyCode;
	//alert(unicodes);
	if (unicodes!=8)
	{ //backspace			
	        if(unicodes!=32)
	            return true;
			else{
				if(events.charCode == 0)
					return true;
				else	
					return false; 
			}
	}
}
function chkPrice(obj,events)
{
	//alert(obj.value);
	var unicodes=events.charCode? events.charCode :events.keyCode;
	//alert(unicodes);
	var getdot =0;
	if (unicodes!=8)
	{ //backspace
	        if((unicodes>47 && unicodes<58 || unicodes == 46 || unicodes == 9)){
				for(i=0;i<obj.value.length;i++){
					if(obj.value[i] == "."){
						getdot = getdot+1;
					}					
				}
				if(getdot > 0 && unicodes == 46){
					if(events.charCode == 0)
						return true;
					else	
						return false;
				}else{
					return true;
				}	            
			}else{			
				if(events.charCode == 0)
					return true;
				else	
					return false; 
			}	
	}
}

function fillState(control, statcode, val,flag)
{
	control.options.length = 0;
	control.options[0] = new Option("---"+LBL_SELECT_CITY+"---");
	control.options[0].value = "";
	for(i=0,j=0; i<stateArr.length; i++)
	{
		if(stateArr[i][0] == val)
		{
			if(statcode == stateArr[i][3])
			{
				control.options[j+1] = new Option( stateArr[i][2]);
				control.options[j+1].value = stateArr[i][3];
				control.options[j+1].selected = true;
			}
			else
			{
				
				control.options[j+1] = new Option( stateArr[i][2]);
				control.options[j+1].value = stateArr[i][3];
			}				
			j++;
		}
	}	
	/*control.options[j+1] = new Option("Other");
	control.options[j+1].value = "Other";
	if(statcode == "Other")
	{
		control.options[j+1].selected = true;
		
	}*/
	
}

function GetCookieForTab(name)
{ 
	var start = document.cookie.indexOf(name+"="); 
	var len = start+name.length+1; 
	if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
	if (start == -1) return null; 
	var end = document.cookie.indexOf(";",len); 
	if (end == -1) end = document.cookie.length; 
	return unescape(document.cookie.substring(len,end)); 
} 


var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + //all caps
"abcdefghijklmnopqrstuvwxyz" + //all lowercase
"0123456789+/=";
function decode64(inp)
{
	var out = ""; //This is the output
	var chr1, chr2, chr3 = ""; //These are the 3 decoded bytes
	var enc1, enc2, enc3, enc4 = ""; //These are the 4 bytes to be decoded
	var i = 0; //Position counter

	// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	var base64test = /[^A-Za-z0-9\+\/\=]/g;

	if (base64test.exec(inp)) { //Do some error checking
	alert("There were invalid base64 characters in the input text.\n" +
	"Valid base64 characters are A-Z, a-z, 0-9, ?+?, ?/?, and ?=?\n" +
	"Expect errors in decoding.");
	}
	inp = inp.replace(/[^A-Za-z0-9\+\/\=]/g, "");
	
	do { //Here’s the decode loop.
	
	//Grab 4 bytes of encoded content.
	enc1 = keyStr.indexOf(inp.charAt(i++));
	enc2 = keyStr.indexOf(inp.charAt(i++));
	enc3 = keyStr.indexOf(inp.charAt(i++));
	enc4 = keyStr.indexOf(inp.charAt(i++));

	//Heres the decode part. There’s really only one way to do it.
	chr1 = (enc1 << 2) | (enc2 >> 4);
	chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
	chr3 = ((enc3 & 3) << 6) | enc4;
	
	//Start to output decoded content
	out = out + String.fromCharCode(chr1);
	
	if (enc3 != 64) {
	out = out + String.fromCharCode(chr2);
	}
	if (enc4 != 64) {
	out = out + String.fromCharCode(chr3);
	}

	//now clean out the variables used
	chr1 = chr2 = chr3 = "";
	enc1 = enc2 = enc3 = enc4 = "";
	
	} while (i < inp.length); //finish off the loop
	//Now return the decoded values.
	return out;
}

function clearField(frmObj){
	frmObj.reset()
}

function removespace(event)
{
	val = event.keyCode;
	 var val=event.charCode? event.charCode :event.keyCode;	
  	if(val == "32")
	{
		//event.keyCode=0;
		return false;
	}
	else
	{
		return true;
	}
}
function phoneformate(value,length)
{
	chk1="1234567890()- ";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function checkValidZipDigit(events) 
{
var unicodes=events.charCode? events.charCode :events.keyCode;
//alert(unicodes);
//return false;
	if (unicodes!=8)
	{ //backspace
	        if( (unicodes>47 && unicodes<58) || (unicodes>96 && unicodes<123) || (unicodes>64 && unicodes<91) || unicodes == 46 || unicodes == 32 || unicodes == 9)
	            return true;
			else
				return false; 
	}
}

function checkValidPhone(events){
	var unicodes=events.charCode? events.charCode :events.keyCode;
	if (unicodes!=8)
	{ //backspace
       if(unicodes>47 && unicodes<58 || unicodes == 46 || unicodes == 40 || unicodes == 41 || unicodes == 45|| unicodes == 43|| unicodes ==32||unicodes==13)
            return true;
		else
			return false; 
	}
}
function chechValidWebsite(events){
	var unicodes=events.charCode? events.charCode :events.keyCode;
	if (unicodes!=8)
	{ //backspace
        if( (unicodes>47 && unicodes<58) || (unicodes>96 && unicodes<123) || (unicodes>64 && unicodes<91) || unicodes == 46 || unicodes == 32 || unicodes == 9 || unicodes == 58 || unicodes == 47)
            return true;
		else
			return false; 
	}
}

function getPriceDigit(events){
	var unicodes=events.charCode? events.charCode :events.keyCode;
	if (unicodes!=8)
	{ //backspace
       if(unicodes>47 && unicodes<58 || unicodes == 9 || unicodes ==46 )
            return true;
		else
			return false; 
	}
}

function limitText(limitField,limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
		return false;
	}
}

/*
function CreateBookmarkLink()
 { 
 	var ua=navigator.userAgent.toLowerCase();
	var isSafari=(ua.indexOf('webkit')!=-1);
	title = "Kiskoo"; 
	url = SITE_URL;
	
	if (window.sidebar)
		window.sidebar.addPanel(title, url,""); 
	else if(window.external)
		window.external.AddFavorite( url, title); 
	else if(window.opera && window.print)  	// Opera Hotlist 
		return true; 
	else if(isSafari)
		alert("You need to Presss Ctrl +D ;");
}*/


/* To get relative Combo */
function getRelativeCombo(id,selectedCat,combId,comboText){
	var val =id;
	if(document.getElementById(""+combId+"")){
		var control	=	document.getElementById(""+combId+"");
		control.options.length = 0;
		control.options[0] = new Option("---"+LBL_SELECT_MODEL+"---");
		control.options[0].value = "";
		for(i=0,j=0; i< genArr.length; i++)
		{	
			if(genArr[i][3] == val)
			{
				if(selectedCat == genArr[i][1])
				{
					control.options[j+1] = new Option(genArr[i][1]);
					control.options[j+1].value = genArr[i][1];
					control.options[j+1].selected = true;
				}else
				{
					control.options[j+1] = new Option(genArr[i][1]);
					control.options[j+1].value = genArr[i][1];
				}				
				j++;
			}
		}
	}	
}

function showSubCategory(id,isubid,isecSub){
	if(document.getElementById('subCatrow'+id)){
		if(document.getElementById('subCatrow'+id).style.display == 'none'){
			document.getElementById('subCatrow'+id).style.display = '';
			
		}else{
			document.getElementById('subCatrow'+id).style.display = 'none';
			
		}
	
	}
	if(document.getElementById('subCatrow'+isubid)){
		if(document.getElementById('subCatrow'+isubid).style.display == 'none'){
			document.getElementById('subCatrow'+isubid).style.display = '';
		}else{
			document.getElementById('subCatrow'+isubid).style.display = 'none';
		}	
	}
	if(document.getElementById('subCatrow'+isecSub)){
		if(document.getElementById('subCatrow'+isecSub).style.display == 'none'){
			document.getElementById('subCatrow'+isecSub).style.display = '';
		}else{
			document.getElementById('subCatrow'+isecSub).style.display = 'none';
		}	
	}
}



function Make_Price(price,type)
{
	price = addCommas(price);
	if(type == '')
		type = "RD $";
	else
		type = type;
	return type+" "+price+""+".00";
}
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


function chkCharUser(events) 
{
var unicodes=events.charCode? events.charCode :events.keyCode;
	 //alert(unicodes);
/*return false; */
	if (unicodes!=8)
	{ //backspace
	        if((unicodes>31 && unicodes<46) || unicodes == 94 || unicodes == 61 || unicodes == 95 || unicodes == 64 || unicodes == 96) {
					
				if(unicodes != 45 && unicodes != 95){
				//alert(unicodes);
					return false;
				}else{					
					return true;
				}	            
			}else{
			
				return true; 
			}	
	}
}


function checkDigit(events) 
{
var unicodes=events.charCode? events.charCode :events.keyCode;
	if (unicodes!=8)
	{ //backspace
	        if( (unicodes>47 && unicodes<58 || unicodes == 46 || unicodes == 39 || unicodes == 37 || unicodes == 9))
			{
	            return true;
			}
			else
				return false; 
	}
}
function checkSecurityDigit(events,id,val) 
{
	
var chkid =id;
var unicodes=events.charCode? events.charCode :events.keyCode;
	if (unicodes!=8)
	{ //backspace
	        if( (unicodes>47 && unicodes<58 || unicodes == 46 || unicodes == 39 || unicodes == 37 || unicodes == 9))
			{
					var newchkid = chkid.substr(0,(chkid.length-1));
					if(navigator.appName == 'Microsoft Internet Explorer'){
						var chkdigit = '3';
					}else{
						var chkdigit = '2';
					}
					if(val.length == chkdigit && chkid == newchkid+'1')
					{
						document.getElementById(newchkid+'2').focus();
					}
					if(navigator.appName == 'Microsoft Internet Explorer'){
						var chkdigit_new = '7';
					}else{
						var chkdigit_new = '6';
					}
					if(val.length == chkdigit_new && chkid == newchkid+'2')
					{
						document.getElementById(newchkid+'3').focus();
					}
	            return true;
			}
			else
				return false; 
	}
}

function checkEnter(events) 
{
	var unicodes=events.charCode? events.charCode :events.keyCode;
	//alert(unicodes);
	if( (unicodes != 13)){
		return true;
	}else{
		return false; 
	}	
}

function limitChars(textarea, limit, infodiv){
	 var text = textarea.value; 
	 var textlength = text.length;
	 var info = document.getElementById(infodiv);
	   
	 if(textlength > limit){
	 	//info.innerHTML = 'You cannot write more then '+limit+' characters!';
	 	textarea.value = text.substr(0,limit);
	 	return false;
	 }else{
		 info.innerHTML = ''+LBL_COMMENT_YOU_HAVE+' <font color="#EC6912">'+ (limit - textlength) +'</font> '+LBL_COMMENT_CHARACTERS_LEFT+'';
	 	 return true;
	 }
}
