function valid(actPath)
{	
	if(Trim(document.frmlist.keyword.value)=="")
	{
		alert("Please Enter keyword for Search.");
		document.frmlist.keyword.value="";
		document.frmlist.keyword.focus();
		return false;
	}
	document.frmlist.keyword.value = Trim(document.frmlist.keyword.value);
	document.frmlist.mode.value="Search";
	if(actPath)
	{
		window.location=actPath +"&option="+document.frmlist.option.value+"&keyword="+document.frmlist.keyword.value;
		return false;
	}
}

function RedirectURL(URL,ExtraParam)
{
	if(!ExtraParam)ExtraParam='';
	window.location=URL+ExtraParam;
	return false;
}
function Trim(s) 
{
	return s.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function pollwin(url,w, h, win_name)
{
	pollwindow=window.open(url,win_name,'top=0,left=0,status=no,toolbars=no,scrollbars=no,width='+w+',height='+h+',maximize=no,resizable="no"');
	pollwindow.focus();
}

/* Added By chetan  
Purpose : Checking for obj availabe and Its Not Blank Value*/
function checkValidNull(obj, msg)
{
	if(obj)
	{
		if(Trim(obj.value)=="")
		{
			alert(msg);
			obj.focus();
			return false;
		}
	}
	else
		return false;	
	return true;	
}


function checkValidZero(obj, msg)
{
	if(obj)
	{
		if(Trim(obj.value)=="" || Trim(obj.value)=="0")
		{
			alert(msg);
			obj.focus();
			return false;
		}
	}
	else
		return false;	
	return true;	
}


/* It is compare the condition (equal,greater,less) 
Parameter : Objname,
comparision value
condition pass 'Equal', 'Greater','Less'
Alere Message to Dipslay
*/
function checkValidCompare(obj,comparewithvalue,condition, msg)
{
	if(obj)
	{
		val=obj.value;
		flag=false;
		if(condition=='Equal' && val==comparewithvalue)
			flag=true;
		if(condition=='Greater' && val >= comparewithvalue)
			flag=true;
		if(condition=='Less' && val< comparewithvalue)
			flag=true;
		if(condition=='LessEqual' && val<= comparewithvalue)
			flag=true;
		if(flag)
		{
			alert(msg);
			obj.focus();
			return false;
		}
		else
			return true;	
	}
	else
		return false;	
}

//Comapre digits
function checkValidDigitCompare(obj,comparewithvalue,condition, msg)
{
	if(obj)
	{
		val=parseInt(obj.value);
		compareval=parseInt(comparewithvalue);
		flag=false;
		if(condition=='Equal' && val==compareval)
			flag=true;
		if(condition=='Greater' && val > compareval)
			flag=true;
        if(condition=='GreaterEqual' && val >= compareval)
			flag=true;
		if(condition=='Less' && val< compareval)
			flag=true;
		if(condition=='LessEqual' && val<= compareval)
			flag=true;
		if(flag)
		{
			alert(msg);
			obj.focus();
			return false;
		}
		else
			return true;
	}
	else
		return false;

}

function checkValidLength(obj,len, msg)
{
	if(obj)
	{
		val=Trim(obj.value);
		if(val=="" || val.length<len )
		{
			alert(msg);
			obj.focus();
			return false;
		}
	}
	else
		return false;	
	return true;	
}
function checkValidNumber(obj, msg)
{   
    chk1="1234567890";
	flag=false;
	if(obj)
	{
		value=obj.value;
		if(value!="")
		{
			len=obj.value.length;
			//alert(len);
			for(i=0;i<len;i++)
			{
				ch1=value.charAt(i);
				rtn1=chk1.indexOf(ch1);
				if(rtn1==-1)
					flag=true;
			}
		}
	}else{
		flag=true;
		msg='Object is not Avaible';
	}
	if(flag)
	{
		alert(msg);
		obj.focus();
		return false;
	}
	return true;
}
function checkValidFloatNumber(obj, msg)
{
	chk1="1234567890.";
	flag=false;
	if(obj)
	{
		value=obj.value;
		if(Trim(value)!="")
		{
			len=obj.value.length;
			//alert(len);
			for(i=0;i<len;i++)
			{
				ch1=value.charAt(i);
				rtn1=chk1.indexOf(ch1);
				if(rtn1==-1)
					flag=true;
			}
		}else flag=true;
	}else{
		flag=true;
		msg='Object is not Avaible';
	}
	if(flag)
	{
		alert(msg);
		obj.focus();
		return false;
	}
	return true;
}
function checkValidPhoneFormate(obj, msg)
{
	chk1="+.1234567890()- ";
	flag=false;
	if(obj)
	{
		value=obj.value;
		if(Trim(value)!="")
		{
			len=obj.value.length;
			for(i=0;i<len;i++)
			{
				ch1=value.charAt(i);
				rtn1=chk1.indexOf(ch1);
				if(rtn1==-1)
					flag=true;
			}
		}
	}else{
		flag=true;
		msg='Object is not Avaible';
	}
	if(flag)
	{
		alert(msg);
		obj.focus();
		return false;
	}
	return true;
}


function alphanum(value,length)
{
	chk1="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_\-";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
//To check only alpha characters added by EMP-082 on 01-02-07
function alpha(value,length)
{
	chk1="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_\- ";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}


function openLoadingWindow(loadMsg)
{
	if(loadMsg)
		loadMsg += " Loading..." ;
	else
		loadMsg = "Loading...";
	winObj=window.open("",0,"menubar=no,resiable=no,width=320,height=10,top=50,left=50");
	//	winObj.document.write("<style>BODY {FONT-FAMILY: Arial, Helvetica, sans-serif; }</style><body bgcolor='#FDFCD9'><table width=100%><tr><Td align=center><h1>Loading....</h1></TD></tr></table></body>");
	winObj.document.write("<style>BODY {FONT-FAMILY: Arial, Helvetica, sans-serif; }</style><body bgcolor='#FDFCD9'><h1><span id='load_div'></span></h1><script>word=new String('"+loadMsg+"');i=0;function showMessage(){if(i>word.length)i=0;document.getElementById('load_div').innerHTML=word.substring(0,i);i++;window.setTimeout('showMessage()', 40);}showMessage();</script>");
	return winObj;
}
function closeLoadingWindow(winObj)
{
	winObj.close();
}
function Highlight(e)
{
	if(e.className!="raw_selectedbg")
		e.className="mouseover";
}
function UnHighlight(e,classname)
{
//	alert(e.className)
	if(e.className!="raw_selectedbg")
		e.className=classname;
}

function openPopupImageWindow(ImageName,ImagePath)
{
	s=window.open('popup.php?page=enlarge&pid=1&amp;h=700&amp;w=700&amp;popup=1&amp;vImage='+ImageName+'&amp;vImagepath='+ImagePath,'enlarged_view','toolbar=no,resizable=yes,scrollbars=yes,width=700, height=700');
    
	s.focus();
	return false;
}
function openPopupImageWindow1(ImageName,ImagePath)
{
	s=window.open('popup1.php?page=enlarge&pid=1&amp;h=800&amp;w=800&amp;popup=1&amp;vImage='+ImageName+'&amp;vImagepath='+ImagePath,'enlarged_view','toolbar=no,resizable=yes,scrollbars=yes,width=700, height=700');

	s.focus();
	return false;
}

/*	End Fucntion */

//To get Niches Sub Categories
function getNiches(niche)
{
    var url = "getniche.php?Code=";
	var extUrl="";
	extUrl="&mode=Add";
	if(document.getElementById("mode").value=="Update") {
extUrl="&hidNichetype="+document.getElementById("hideNicheTypeId").value+"&mode=Update&iCoachId="+
        document.getElementById("iCoachId").value;
	}
	var isWorking = false;
    if(niche!=""){
        if (!isWorking)
        {
    	   catID = niche;
        	isWorking = true;
        	url += catID+extUrl;
  			if (window.XMLHttpRequest)
    		{
    			http=new XMLHttpRequest()
    		  	http.open("GET",url, true);
    			http.onreadystatechange=handleHttpResponseprice
    			http.send(null)
    		}// code for IE
    		else if (window.ActiveXObject){
    		  	http=new ActiveXObject("Microsoft.XMLHTTP")
    		    if (http){
    		    	http.open("GET",url, true);
    		    	http.onreadystatechange=handleHttpResponseprice
    		    	http.send()
    		    }
			}
	   }//end if(!working))
  }//end if(iid!="")
}
function handleHttpResponseprice()
{
		var temp;
		var tmp_color;
		if (http.readyState == 4)
		{
			var xmlDocument = http.responseXML;
		    //alert(http.responseText);
			var no = xmlDocument.getElementsByTagName('enicheid').length;
			var cs=xmlDocument.getElementsByTagName('cs').item(0).firstChild.data;
			var selectoption=xmlDocument.getElementsByTagName('selectoption').item(0).firstChild.data;
			var othval=xmlDocument.getElementsByTagName('othval').item(0).firstChild.data;
			document.getElementById("NicheSubcat").innerHTML=selectoption;
			if(othval==0)
	       		document.getElementById("othNicheid").style.display="none";
			if(othval==1)
    			document.getElementById("othNicheid").style.display="";
		}
}


function getNiche(niche)
{
     if(document.getElementById("vNiche").value=="")
    {
        //alert("Select Niche/Specialties");
        document.getElementById("vNiche").focus();
        return false;
	}
//	alert(niche);
	var url ="getNicheSubCategories.php?search=search&Code=";
//	alert(url);
	var isWorking = false;
	if (!isWorking)
	{
		catID = niche;
			isWorking = true;
			url += catID;
            //alert(url)
			if (window.XMLHttpRequest)
		  	{
		  		http=new XMLHttpRequest()
		  		http.open("GET",url, true);
			  	http.onreadystatechange=handleHttpResponse5
			  	http.send(null)
		  	}
			// code for IE
			else if (window.ActiveXObject)
		  	{
		  		http=new ActiveXObject("Microsoft.XMLHTTP")
		    	if (http)
		    	{
		    		http.open("GET",url, true);
		    		http.onreadystatechange=handleHttpResponse5
		    		http.send()
		    	}
		  	}
  	}//end if(!working))
	//if(!displayPopup)	closeLoadingWindow(winObj);
}//end functiongetStateName()
function handleHttpResponse5()
{
		var temp;
		var tmp_color;
		if (http.readyState == 4)
		{
			var xmlDocument = http.responseXML;
            //alert(http.responseXML);
		    //alert(http.responseText)
			var no = xmlDocument.getElementsByTagName('tot').item(0).firstChild.data;
			temp="<select name=niche id=NicheSubcat1 class=INPUT>";
			temp+="<option value=''>Please Select Niche</option>";
			if(no>0)
			{
				for(i=0;i<no;i++)
				{
					var iPId = xmlDocument.getElementsByTagName('optval').item(i).firstChild.data;
					var PName =xmlDocument.getElementsByTagName('opttext').item(i).firstChild.data;
					temp+="<option value="+iPId+">"+PName+"</option>";
				}
			}else{
				temp +="";
			}
			if(no==0) {
			temp+="";
			}
			temp+="</select>";
			/*
			alert(temp);
			return false;
			*/
			document.getElementById("NicheSubcat").innerHTML=temp;
		}
}
/*	End Fucntion */

function getNiche1(niche)
{
     if(document.getElementById("vNiche1").value=="")
    {
        //alert("Select Niche/Specialties");
        document.getElementById("vNiche1").focus();
        return false;
	}
//	alert(niche);
	var url ="getNicheSubCategories.php?search=search&Code=";
//	alert(url);
	var isWorking = false;
	if (!isWorking)
	{
		catID = niche;
			isWorking = true;
			url += catID;
            //alert(url)
			if (window.XMLHttpRequest)
		  	{
		  		http=new XMLHttpRequest()
		  		http.open("GET",url, true);
			  	http.onreadystatechange=handleHttpResponse8
			  	http.send(null)
		  	}
			// code for IE
			else if (window.ActiveXObject)
		  	{
		  		http=new ActiveXObject("Microsoft.XMLHTTP")
		    	if (http)
		    	{
		    		http.open("GET",url, true);
		    		http.onreadystatechange=handleHttpResponse8
		    		http.send()
		    	}
		  	}
  	}//end if(!working))
	//if(!displayPopup)	closeLoadingWindow(winObj);
}//end functiongetStateName()
function handleHttpResponse8()
{
		var temp;
		var tmp_color;
		if (http.readyState == 4)
		{
			var xmlDocument = http.responseXML;
		   //alert(http.responseText)
			var no = xmlDocument.getElementsByTagName('tot').item(0).firstChild.data;
			temp="<select name=niche1 id=NicheSubcat2 class=INPUT>";
			temp+="<option value=''>Please Select Niche</option>";
			if(no>0)
			{
				for(i=0;i<no;i++)
				{
					var iPId = xmlDocument.getElementsByTagName('optval').item(i).firstChild.data;
					var PName =xmlDocument.getElementsByTagName('opttext').item(i).firstChild.data;
					temp+="<option value="+iPId+">"+PName+"</option>";
				}
			}else{
				temp +="";
			}
			if(no==0) {
			temp+="";
			}
			temp+="</select>";
			/*
			alert(temp);
			return false;
			*/
			document.getElementById("NicheSubcat3").innerHTML=temp;
		}
}
/*	End Fucntion */

function openWindow(destination,height, width)
 {
	var targetWindow = destination;
	var x = Math.random();
	x = x * 1000;
	x = Math.round(x);
	var wind = "window" + x
	temp = window.open(targetWindow, wind, config='height=' + height + ',width=' + width + ',toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no, directories=no,status=yes,left=50,top=50');
}
/*Check Image Size*/
function imageProperty(url,wid,hig)
{
	myImage = new Image() 
	myImage.src = url; 
	if(myImage.width >wid){
		alert("You Can't upload image of "+ myImage.width +" Width");
		return false;
	}
	if(myImage.height >hig){
		alert("You Can't upload image of "+ myImage.height +" Hight");
		return false;
	}
}

//Added by EMP/82 on 3/01/2007
function checkValidImage(imageobj,iwidth,iheight)
{
 
  /*
window.open('ImageValid.php?vImagepath='+imageobj.value);
  return false;
*/
    var msg="";
     var myImage;
     var error;
     myImage = new Image();
     myImage.src=imageobj.value;
     if(myImage.width > iwidth)
     {
        msg="Image width must be "+iwidth+"Px\n";
        error=1;
     }
     if(myImage.height>iheight)
     {
       msg+="Image Height must be"+iheight+"Px";
        error=1;
     }
     if(error)
        {
          alert(msg);
          return false;
        }
    else
        return true;
}

function wordCount(what ,maxKeys)
{
	var str = new String(what.value);
 	var len = str.length;
	var fullStr = what.value + " ";
	var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
	var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
	var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
	var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
	var splitString = cleanedStr.split(" ");
	var word_count = splitString.length -1;
	maxKeys=maxKeys;
	 if (word_count == maxKeys)
     {                               
       alert("Content should be"+maxKeys+"words");
       return false;
 	}

}

function onlynumber(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 CheckQuantity(form,Totalbook,Totalsandw)
{
    var Totalbooks=Totalbook;
    if(Totalbooks>0)
    {
        for(i=0;i<Totalbooks;i++)
        {
            if( !checkValidZero(document.getElementById("UpdateQ"+i),"Enter Valid Number Item Should Atleast one") )
            {  
                return false;
            }
       }
    }
      if(Totalsandw>0)
    {
        for(i=0;i<Totalsandw;i++)
        {
            if( !checkValidZero(document.getElementById("UpdateseminarQ"+i),"Enter Valid Number Item Should Atleast one") )
            {  
                return false;
            }
       }
    }
    if(form=="CheckOut")
    {
       document.cartform.action="index.php?file=co-co_orderdetails";
       document.cartform.submit();
	   return false;
  }
  if(form=="EmptyCart")
    {
   	 document.cartform.action="index.php?file=co-co_cart&EmptyCart=EmptyCart";
    }

    if(form=="KeepShopping")
    {
  	 document.cartform.action="index.php?file=co-co_findcoach";
    }
  else
    {
       document.cartform.submit();
    }
}


function UpdateQuantityValue(elememts,event)
{
    if(event.keyCode==8 || event.keyCode==13 ||event.keyCode==46 ||event.keyCode==37 || event.keyCode==39)
    return false;
    var flag=false;
    var val=elememts.value;
    var Id=elememts.id;//To get the qty value
    var tid="tid"+Id.substr(3,Id.length);//to get the prev qty value
    if(val==""||val=="0")
    {
        alert(" Number Should be Greater Than Zero To Move On");
        flag=true;
        document.getElementById(elememts.id).value=document.getElementById(tid).value;
        
    }
    if(!(event.keyCode>47 &&event.keyCode<58))
    {
		if(!(event.keyCode>96 &&event.keyCode<105))
    	{
        	alert("Quantity Should be in only Digits");
        	flag=true;
        	document.getElementById(elememts.id).value=document.getElementById(tid).value;
		}
    }
    if(flag==true)
    {
      elememts.focus();
    }
}
function checknullvalue(frm)
{ var i;var j=0;
   for(i=0;i<frm.length;i++)
   { 
     if(frm.elements[i].name=="update"+j)
     {
     var qty="qty"+j;
     if(document.getElementById(qty).value=='')
       {
         document.getElementById(qty).value=1;
       }j++;
     }
   }

}

function checkDelete(index)
{

  	ans = confirm("Confirm Deletion of Selected Record(s) ?");
   if(ans != true)
  {
   	return false;
  }
  else
  window.location="index.php?file=co-co_cart&mode=Delete&DelId="+index;
}
function getCheckCount()
{	var x=0;

	for(i=0;i < document.cartform.elements.length;i++)
	{
       if(document.cartform.elements[i].type=="checkbox")
       {
         if(document.cartform.elements[i].checked)
           {
             x++;
           }
        }
	}
	return x;
}

var http;
function getRegions(Country)
{

	if(document.getElementById("vCountryCode").value=="") {
	 alert("Select Country");
	 //document.getElementById("disStates").innerHTML="";
	// document.getElementById("disCity").innerHTML="";
	 document.getElementById("vCountryCode").focus();
	 return false;
	}
	var url ="getRegion.php?Code=";
	//alert(url);
	var isWorking = false;
	if (!isWorking)
	{
		catID = Country;
			isWorking = true;
			url += catID;
			//alert(url);
			if (window.XMLHttpRequest)
		  	{
		  		http=new XMLHttpRequest()
		  		http.open("GET",url, true);
			  	http.onreadystatechange=handleHttpResponseRegion
			  	http.send(null)
		  	}
			// code for IE
			else if (window.ActiveXObject)
		  	{
		  		http=new ActiveXObject("Microsoft.XMLHTTP")
		    	if (http)
		    	{
		    		http.open("GET",url, true);
		    		http.onreadystatechange=handleHttpResponseRegion
		    		http.send()
		    	}
		  	}
  	}//end if(!working))
	//if(!displayPopup)	closeLoadingWindow(winObj);
}//end getCountryName()
function handleHttpResponseRegion()
{
		var temp;
		var tmp_color;
		if (http.readyState == 4)
		{

			//var xmlDocument = http.responseXML;
			//alert(http.responseText);
			 //var no = xmlDocument.getElementsByTagName('rid').length;
			 //alert( xmlDocument.getElementsByTagName('rid').length);
			 
			//var no1=xmlDocument.getElementsByTagName('tot').length;
			//alert(xmlDocument.getElementsByTagName('text').item(0).firstChild.data);
		    //var no = xmlDocument.getElementsByTagName('reg').item(0).firstChild.data;
			//alert(no);
            temp='<select name="region" class="INPUT" style="width: 170px;" id="region">';
			temp+="<option value=''>Please Select State/District</option>";
			temp+=http.responseText;
			
			//if(no > 0)
			//{
			//	for(i=0;i<no;i++)
			//	{
			//		var iPId = xmlDocument.getElementsByTagName('rid').item(i).firstChild.data;
			//		var PName =xmlDocument.getElementsByTagName('regn').item(i).firstChild.data;
			//		temp+="<option value="+iPId+">"+PName+"</option>";
					
			//	}
			//}else{
			//	temp +="";
			//}
			//if(no==0) {
			//temp+="<option value='otherRegion'>Other Region</option>";
			//}
			temp+="</select>";
			/*
			alert(temp);
			return false;
			*/
			document.getElementById("vRegion2").innerHTML=temp;
		}
	}
/*	End Fucntion */


function getRegionsR(Country)
{

	if(document.getElementById("vCountryCode").value=="") {
	 alert("Select Country");
	 //document.getElementById("disStates").innerHTML="";
	// document.getElementById("disCity").innerHTML="";
	 document.getElementById("vCountryCode").focus();
	 return false;
	}
	var url ="/getRegionR.php?Code=";
	//alert(url);
	var isWorking = false;
	if (!isWorking)
	{
		catID = Country;
			isWorking = true;
			url += catID;
			//alert(url);
			if (window.XMLHttpRequest)
		  	{
		  		http=new XMLHttpRequest()
		  		http.open("GET",url, true);
			  	http.onreadystatechange=handleHttpResponseRegion
			  	http.send(null)
		  	}
			// code for IE
			else if (window.ActiveXObject)
		  	{
		  		http=new ActiveXObject("Microsoft.XMLHTTP")
		    	if (http)
		    	{
		    		http.open("GET",url, true);
		    		http.onreadystatechange=handleHttpResponseRegion
		    		http.send()
		    	}
		  	}
  	}//end if(!working))
	//if(!displayPopup)	closeLoadingWindow(winObj);
}//end getCountryName()
function handleHttpResponseRegion()
{
		var temp;
		var tmp_color;
		if (http.readyState == 4)
		{

			//var xmlDocument = http.responseXML;
			//alert(http.responseText);
			 //var no = xmlDocument.getElementsByTagName('rid').length;
			 //alert( xmlDocument.getElementsByTagName('rid').length);
			 
			//var no1=xmlDocument.getElementsByTagName('tot').length;
			//alert(xmlDocument.getElementsByTagName('text').item(0).firstChild.data);
		    //var no = xmlDocument.getElementsByTagName('reg').item(0).firstChild.data;
			//alert(no);
            temp='<select name="region" class="INPUT" style="width: 170px;" id="region">';
			temp+="<option value=''>Please Select State/District</option>";
			temp+=http.responseText;
			
			//if(no > 0)
			//{
			//	for(i=0;i<no;i++)
			//	{
			//		var iPId = xmlDocument.getElementsByTagName('rid').item(i).firstChild.data;
			//		var PName =xmlDocument.getElementsByTagName('regn').item(i).firstChild.data;
			//		temp+="<option value="+iPId+">"+PName+"</option>";
					
			//	}
			//}else{
			//	temp +="";
			//}
			//if(no==0) {
			//temp+="<option value='otherRegion'>Other Region</option>";
			//}
			temp+="</select>";
			/*
			alert(temp);
			return false;
			*/
			document.getElementById("vRegion2").innerHTML=temp;
		}
	}
/*	End Fucntion */
