// JavaScript Document
function validateEmail(txtVal,siteurl,error_content,msg)
{	
	val	= txtVal;
	var errorImage = "<img src='"+siteurl+"/images/error.png' align='absmiddle'> ";
	var emailStr = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	if(val.length == 0 )
	{
		document.getElementById(error_content).innerHTML= errorImage+"Please enter "+msg+".";
	}
	else
	{
		if (emailStr.test(val) == false)
		{
			document.getElementById(error_content).innerHTML= errorImage+"Please enter valid "+msg+".";
		}else
		{
			document.getElementById(error_content).innerHTML="";
		}
	}//else
}

String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
	};
		
function is_blank(value,siteurl,error_content,msg) 
{
	//var frm_hid_fld_name=eval(hid_fld_name);
	val	= value;
	var errorImage = "<img src='"+siteurl+"/images/error.png' align='absmiddle'> ";
	
	val = val.replace(/^\s+/, '');
	val.replace(/\s+$/, '');

	if(val.length == 0 ) 
	{ 
		if(msg == "country")
			document.getElementById(error_content).innerHTML=errorImage+"Please select "+msg+".";
		else
			document.getElementById(error_content).innerHTML=errorImage+"Please enter "+msg+".";
	}
	else
	{
		document.getElementById(error_content).style.display="none";
	}
}

function isBlankNumeric(txtVal,msg,divname,selEnter) 
{
	val	= txtVal;
	val = val.replace(/^\s+/, '');
	val.replace(/\s+$/, '');
	if(val.length == 0 ) 
	{ 
		document.getElementById(divname).innerHTML="Please "+selEnter+" "+msg+".";
		document.getElementById(divname).style.display="block";
	}
	else if(isNaN(val))
	{
		document.getElementById(divname).innerHTML="Please "+selEnter+" only numeric values for "+msg+".";
		document.getElementById(divname).style.display="block";		
	}
	else
	{
		document.getElementById(divname).innerHTML= "";
		document.getElementById(divname).style.display="none";
	}
}

//Code For Check username is already Exists or not
function chkUserName(value,siteurl,error_content)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url=siteurl+"/page_include/user_validations.php"

	url=url+"?username="+value;
	
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			document.getElementById(error_content).innerHTML = xmlHttp.responseText;
		}
		else
		{
			document.getElementById(error_content).innerHTML="<img src='"+siteurl+"/images/loading_user.gif'>";
		}
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function chkBothConfirm(confirmval,siteurl,val,error_content,msg)
{
	var val;
	var confirmval;
	
	confirmval = confirmval.replace(/^\s+/, '');
	confirmval.replace(/\s+$/, '');
	
	val = val.replace(/^\s+/, '');
	val.replace(/\s+$/, '');	
	
	var errorImage = "<img src='"+siteurl+"/images/error.png' align='absmiddle'> ";
	
	if(confirmval.length == 0 ) 
	{ 
		document.getElementById(error_content).innerHTML= errorImage+"Please enter confirm "+msg+".";
	}
	else
	{
		if(val != confirmval ) 
		{ 
			var msg;
			//document.getElementById(error_content).innerHTML= errorImage+"passwrod & confirm password should be same. "+msg;		
			document.getElementById(error_content).innerHTML= errorImage+"Password & confirm password should be same."					
		}
		else
		{
			document.getElementById(error_content).style.display="none";
		}
	}
}

function alphanumeric(txtVal,msg,divname)
{
	var value	= txtVal;
	var parseval= "Y";

	if(value == '')
	{
		document.getElementById(divname).innerHTML="Please enter "+msg+".";
		document.getElementById(divname).style.display="block";
		return false;
	}
	else
	{
		for(var j=0; j<value.length; j++)
		{
			var value_char = value.charAt(j);
			var hh = value_char.charCodeAt(0);
			if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123) ||(hh ==32))
			{
			}
			else
			{
				parseval='N';
				break;
			}
		}
		if(parseval=="N")
		{
			document.getElementById(divname).innerHTML="Please enter valid "+msg+".";
			document.getElementById(divname).style.display="block";
			
		}
		else
		{
			document.getElementById(divname).innerHTML= "";
			document.getElementById(divname).style.display="none";
			return true;
		}
	}
	return true;
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function numeric_valid(txtbox_name,msg)
{
	if(txtbox_name.value == '')
	{
		alert("Please enter the mobile number.");
		txtbox_name.value='';
		return false;
	}
	else if (isNaN(txtbox_name.value))
	{
		alert(msg);
		txtbox_name.value='';
		return false;
	}	
}

function checkAll(tmp_frmName,tmp_chkbox)
{
	frmElement	= eval("document."+tmp_frmName+"['"+tmp_chkbox+"[]']");
	frmName	= eval("document."+tmp_frmName);
	if(frmElement.length)
	{
		for(var i=0;i<frmElement.length;i++)
		{
			if (frmName.chkAll.checked)
				frmElement[i].checked = true;
			else
				frmElement[i].checked = false;
		}
		
	}
	else
		{
			if (frmName.chkAll.checked)
				frmElement.checked = true;
			else
				frmElement.checked = false;
		}
		
}//chkAll

function mycenteralpopwinVHS(fname,width,height)
{
	var file
	var sWidth	= 200
	var sHeight = 200
	
	if(width.length > 0){
	sWidth = width;
	}
	else{
	width =100;
	}
	
	if(height.length > 0){
	sHeight = height;
	}
	else{
	height =100;
	}
	
	file = fname
	file =file

	var wintop  =window.screen.availHeight;
	var winleft =window.screen.availWidth;
	wintop  =(wintop/2) -(height/2)
	winleft =(winleft/2) -(width/2)

	if ( sWidth > window.screen.availWidth )
		{ sWidth = window.screen.availWidth; }
	if (sHeight > window.screen.availHeight )
		{ sHeight = window.screen.availHeight; }
	if ( parseInt(sWidth) < width )
		{ sWidth = width; }
	if ( parseInt(sHeight) < height )
		{ sHeight = height; }
	
	if ( navigator.appName == "Microsoft Internet Explorer" )
	{ 
		window.open(file, "_blank", "status=no, scrollbars=yes, toolbar=no, resizable=yes, location=no , menubar=no, top=" + wintop + ", left= "+ winleft +",  height=" + sHeight + ", width=" + sWidth); 
	}
	if ( navigator.appName == "Netscape" ) 
	{ 
		window.open(file,"_blank"," scrollbars=yes,resizable=yes,top=" + wintop + ", left= "+ winleft +",alwaysRaised,dependant,innerheight=" + sHeight + ",innerwidth=" + sWidth); 
	}
}



function loadingChiLavoraSearchPage(block,siteUrl) 
{
	var fldAzienda		 = document.getElementById("txt_company").value;
	var fldAgenzia		 = document.getElementById("txt_agency").value;
	var fldSettore  	 = document.getElementById("selSettore").value;
	var fldSottosettore	 = document.getElementById("selSottosettore").value;

	/////if(fldAzienda==" " && fldAgenzia==" " && fldSettore==" " && fldSottosettore==" ")
	if(fldAzienda == "" && fldAgenzia == "" && fldSettore == "" && fldSottosettore == "")	 
	{
		alert("Please enter atleast one value");
		return false;
	}
	
	block_code		= document.getElementById(block);	
	
	block_code.innerHTML = "<div align='center'><img src='"+siteUrl+"/images/loading.gif'></div>";
	url					 = siteUrl+"/page_include/inc_chilavora_search_result.php?azienda="+fldAzienda+"&agenzia="+fldAgenzia+"&settore="+fldSettore+"&sottosettore="+fldSottosettore;
	ajaxFunction(block_code,url);
}


function SearchPagingResult(pagenumber,pageipp,block,siteUrl)
{
	var fldAzienda		 = document.getElementById("txt_company").value;
	var fldAgenzia		 = document.getElementById("txt_agency").value;
	var fldSettore  	 = document.getElementById("selSettore").value;
	var fldSottosettore	 = document.getElementById("selSottosettore").value;

	/////if(fldAzienda==" " && fldAgenzia==" " && fldSettore==" " && fldSottosettore==" ")
	
	
	block_code		= document.getElementById(block);	
	
	block_code.innerHTML = "<div align='center'><img src='"+siteUrl+"/images/loading.gif'></div>";
	url					 = siteUrl+"/page_include/inc_chilavora_search_result.php?azienda="+fldAzienda+"&agenzia="+fldAgenzia+"&settore="+fldSettore+"&sottosettore="+fldSottosettore+"&page="+pagenumber+"&ipp="+pageipp;
	/////siteUrl+"/page_include/inc_search_result.php?networkId="+fldNetworkId+"&manufacturerId="+fldManufacturerId+"&handsetId="+fldHandsetId+"&monthlyCost="+fldMonthlyCost+"&handsetCost="+fldHandsetCost+"&freeTexts="+fldFreeTexts+"&freeMinutes="+fldFreeMinutes+"&page="+pagenumber+"&ipp="+pageipp;
	ajaxFunction(block_code,url);
}

function loadingGlossarySearchPage(block,siteUrl,val,alpha,actNo,permission)
{	
	var permission;
	block_code			 = document.getElementById(block);	
	block_code.innerHTML = "<div align='center'><img src='"+siteUrl+"/images/loading.gif'></div>";
	
	for( i = 65 ; i <= 90; i++ )
	{
		document.getElementById(i).className = "glossario_list";
		if(i==actNo)
		{
			document.getElementById(i).className = "glossario_list_active";
		}
	}
	
	if(alpha == "")
	{
		if(val==0)
		{
			//url				 = siteUrl+"/page_include/inc_glossario_search_result.php?permission="+permission;
			url				 = siteUrl+"/glossario.php";
		}
		if(val==1)
		{
			var strKeyword	= document.getElementById("txtKeyword").value;
			//url				= siteUrl+"/page_include/inc_glossario_search_result.php?keyWord="+strKeyword+"&permission="+permission;
			url				= siteUrl+"/glossario.php?keyWord="+strKeyword;
		}
	}
	else
	{
		    document.getElementById("txtKeyword").value = "";
			//url				 = siteUrl+"/page_include/inc_glossario_search_result.php?alpha="+alpha+"&permission="+permission;
			url				 = siteUrl+"/glossario.php?alpha="+alpha;
	}
	window.location	= url;
	/////ajaxFunction(block_code,url);	
}

function ajaxFunction(c,url) {

	var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,... 
		http_request = new XMLHttpRequest(); 
		if (http_request.overrideMimeType) { 
			http_request.overrideMimeType('text/xml'); 
		} 
	} else if (window.ActiveXObject) { // IE 
		try { 
			http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
		}
		catch (e) { 
			try { 
				http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
			}
			catch (e) {
				// do nothing
			} 
		}
	}
	if (!http_request) { 
		c.innerHTML = 'Unfortunatelly you browser doesn\'t support this feature.'; 
	} 
	http_request.onreadystatechange = function() 
	{ 
		if (http_request.readyState == 4) {
			if (http_request.status == 200) { 
				c.innerHTML = http_request.responseText; 
			} else { 
				c.innerHTML = 'There was a problem with the request.(Code: ' + http_request.status + ')'; 
			} 
		} 
	}
	http_request.open('GET', url, true); 
	http_request.send(null); 
}

function verifyNumeric(which)
{
	var oldvalue = [''];
    if (isNaN(which.value))
    {
        if (oldvalue[which])
        {
            which.value = oldvalue[which];
        }
        else
        {
            which.value = '';
            oldvalue[which] = '';
        }    
    }
    else
    {
        oldvalue[which] = which.value;
    }
}
function checkStock(stock, productInCart)
{	
	if(stock > productInCart)
	{
		return true;
	}
	else
	{
		alert("Sorry!! We have only "+stock+" item(s) in stock which you have already added in shopping cart.");
		return false;
	}
	
}

function numbersOnly(e)
{
	var uniCode = e.charCode ? e.charCode : e.keyCode;
	
	if(uniCode != 8 && uniCode != 9 && uniCode != 37 && uniCode != 39 && uniCode != 46)
	{
		if(uniCode < 48 || uniCode > 57)
			return false;
	}
}
function checkRadio()  
{ 
  
}
function validateAddToCartWithRadio()
{
 	var checked 	= false; 
	var colorIds	= document.getElementById("txtColorIds").value;
	
	if(colorIds.length > 0)
	{
		var buttons = document.frmDerails.elements.color; 
	  
		for (var i=0; i<buttons.length; i++)  
		{  
			if (buttons[i].checked) {  
				checked = true; 
				break;  
			}
		} 
		if(!checked) 
			alert("Please choose a color.");  
	}
  
  	return checked ;
}

function validateAddToCartWithSelectBox(id)
{
 	var colorIds	= document.getElementById("txtColorIds"+id).value;
	
	if(colorIds.length > 0)
	{
		var color	= document.getElementById("color"+id);
		if ( color.selectedIndex == 0 ) 
		{ 
			alert ( "Please select product color." ); 
			return false; 
		} 
	}
	return true; 
}