// this function is select All And De select All

var selectall;
var deselectall; 
function SelectAllList(selectall)
{
	for(var i = 0;i < selectall.length;i++)
	{
		selectall.options[i].selected = true;
	}
}
function DeselectAllList(deselectall)
{
	for(var i = 0;i < deselectall.length;i++)
	{
		deselectall.options[i].selected = false;
	}
}
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}


function setSelectList(list_arr,selval)
{
	for(i=0;i<list_arr.length;i++)
	{
		if(list_arr[i].value == selval)
		{
			list_arr[i].selected=true;
			break;
		}
	}
}
function valid(actPath)
{	
	//alert(document.frmlist.keyword.value);
	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 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 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;
}

function decimalNumber(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 number(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 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 Trim(s) 
{
	return s.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

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






// This code was written by Tyler Akins and has been placed in the
// public domain.  It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}

/* 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;	
}

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(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;
		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 checkKeyEventNumber()
{  
	val = event.keyCode;
   	if(val==13)	return true;
	if(val<48)	event.keyCode=0;
	if(val>57)	event.keyCode=0;
	return true;
}

function checkKeyEventFloatNumber()
{  
	
	
	//alert(event+" "+navigator.appName);
	var val;
	if (navigator.appName == "Microsoft Internet Explorer")
      val = window.event.keyCode;
   	else if (navigator.appName == "Navigator")
		val = event.which;
   	else if (navigator.appName == "Mozilla")
       val = event.keyCode;
   	else if (navigator.appName == "Netscape")
       val = event.which;

	//alert(val);
	//val = event.keyCode;
   
	if(val==13)		return true;
	if(val<48 && val!=46 && val!=43 && val!=45)
  		event.keyCode=0;
	if(val>57)
		event.keyCode=0;
	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 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 getHTTPObject()
{
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
  	{
  		xmlhttp=new XMLHttpRequest()
  	}
// code for IE
	else if (window.ActiveXObject)
  	{
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  	}
	return xmlhttp;
}
function Highlight(e)
{
	if(e.className!="raw_selectedbg")
		e.className="mouseover";
}
function UnHighlight(e,classname)
{
	if(e.className!="raw_selectedbg")
		e.className=classname;
}
function openPopupImageWindow(ImageName,ImagePath)
{
	s=window.open('popup.php?page=enlarge&pid=1&h=700&w=700&popup=1&vImage='+ImageName+'&vImagepath='+ImagePath,'enlarged_view','toolbar=no,resizable=yes,scrollbars=yes,width=700, height=700'); 
	s.focus();
	return false;
}
function Delete_Image(tablename,fieldname,fieldid,value,Image)
{
	document.frmadd.mode.value='DeleteImage';
	//alert(tablename+" "+fieldname+" "+fieldid+" "+value);
	document.frmadd.TABLENAME.value=tablename;
	document.frmadd.FIELDNAME.value=fieldname;
	document.frmadd.FIELDID.value=fieldid;
	document.frmadd.FIELDVALUE.value=value;
	document.frmadd.IMAGEVALUE.value=Image;
	document.frmadd.submit();
}
/*	added by bhavin	23-jan-2006		*/

function checkObjectNull(obj, msg)
{
	if("undefined" != typeof(obj.type))// If multiple value then return error
	{
		typeVal = obj.type
	}
	else
	{
		typeVal = obj[0].type
	}
	switch(typeVal)
	{
		case "text":
			if(obj.value=="")
			{
				alert(msg);
				obj.focus();
				return false;
			}
			break;
		case "radio":
			var tot = obj.length;
//				alert(tot);
			flag = 0;
			if(tot>0)// Return undefined if array of object 
			{
				for(i=0; i<tot ; i++)
				{
					if(obj[i].checked)
					{
						flag=1;
						break;
					}
				}
			}
			else
			{
				if(obj.checked)
					flag=1;
			}
			if(flag==0)
			{
				alert(msg);
				if(tot>=0) obj[0].focus();
				else obj.focus();
				return false;
			}
			break;
		case "checkbox":
			var tot = obj.length;
//				alert(tot);
			flag = 0;
			if(tot>0)// Return undefined if array of object 
			{
				for(i=0; i<tot ; i++)
				{
					if(obj[i].checked)
					{
						flag=1;
						break;
					}
				}
			}
			else
			{
				if(obj.checked)
					flag=1;
			}
			if(flag==0)
			{
				alert(msg);
				if(tot>=0) obj[0].focus();
				else obj.focus();
				return false;
			}
			break;

		case "select-one":			
			if(obj.selectedIndex==0)
			{
				alert(msg);					
				obj.focus();
				return false;
			}
			break;
		case "textarea":
			if(obj.value=="")
			{
				alert(msg);
				obj.focus();
				return false;
			}
			break;
		case "file":
			if(obj.value=="")
			{
				alert(msg);
				obj.focus();
				return false;
			}			
			break;
	}
	return true;
}

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=yes,location=no, directories=no,status=yes,left=50,top=50');
}
function submenu(fval,tot)
{
	//alert(fval + " --  " +tot);
	//alert(fval);	
	if(typeof(admin_image_url)!='undefined' && admin_image_url!="")
		image_tab_url = admin_image_url;
	else
		image_tab_url = 'images/';
	//alert(image_tab_url)
	if(document.getElementById('TabId'))
		document.getElementById('TabId').value=fval;
	for(i=1;i<=tot;i++)
 	{
		var sample="form"+i;
		//alert(fval + " -- " + i);
		if(parseInt(fval)==parseInt(i))
		{
			document.getElementById(sample).style.display='inline';
		   	document.getElementById("form"+i+"td").background = image_tab_url + 'tab_enable.gif'
			document.getElementById("form"+i+"font").color = '#FFFFFF'			
			if(fval==tot)
			{ document.getElementById("form"+i+"tdright").background = image_tab_url +  'tab_enable-right.gif' }
			else
			{ document.getElementById("form"+i+"tdright").background = image_tab_url +  'tab_enable-right.gif'}
		}
		else
		{
			if(document.getElementById("form"+i+"td").background != (image_tab_url + 'tab_disable.gif'))
			{
				//alert(document.getElementById("form"+i+"td"));
				document.getElementById(sample).style.display='none';
				if(document.getElementById("form"+i+"td").background=="")
					continue;
				document.getElementById("form"+i+"td").background = image_tab_url + 'tab_disable.gif';
				document.getElementById("form"+i+"tdright").background = image_tab_url + 'tab_disable-right.gif';
				document.getElementById("form"+i+"font").color = '#000000'				
			}
		}
		//alert(document.all(sample).style.display + " >> " + i);
	 }
}
/*	End Fucntion */

function formatCurrency(num, decPlaces, decPoint, thousandPoint) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	if(decPlaces=='')
		decPlaces=2;
	sign = (num == (num = Math.abs(num)));
	num = num.toString();
	if(num.indexOf(".")==-1)
		cents = "0";
	else
	{
		cents = num.substring(num.indexOf(".")+1,num.length);
		num = num.substring(0, num.indexOf("."));
	}
	while(cents.length<decPlaces)
	{
		cents = cents + "0";
	}
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3)) + thousandPoint + num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + decPoint + cents.substring(0,decPlaces));
}	

// Created By Ankit Agrawal 
// Date : 3/Oct/2007
function switchto(plink,val){
	window.location=plink+'&iId='+val;
}
function setAllSelected(obj)
{
	var sel_obj = document.getElementById(obj);
	
	for(i=0;i<sel_obj.length;i++)
	{
		sel_obj[i].selected = true;
	}	
}
function setAllDeSelected(obj)
{
	var sel_obj = document.getElementById(obj);
	
	for(i=0;i<sel_obj.length;i++)
	{
		sel_obj[i].selected = false;
	}	
}
function checkAll()
{
	var rs = (document.frmlist.abc.checked)?true:false;
	
	for(i=0;i<document.frmlist.elements.length;i++)
	{
	  	if(document.frmlist.elements[i].id == 'iId')
  		{
			document.frmlist.elements[i].checked = rs;
		}

	}  
}

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
    		    enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

//// Used for FCK Validation with other field Validation
function getfckValid(fckId)
{
	if(FCKeditorAPI.GetInstance(fckId)){
		FCKeditorAPI.GetInstance(fckId); 
		s = FCKeditorAPI.GetInstance(fckId); 
		if(Trim(s.GetXHTML()) == "" || s.GetXHTML() == null) 
			return false;
		else
			return true;
	}else{
		setTimeout("return getfckValid("+fckId+");",100);
	}
}
function EnvcheckAll()
{
	var len ;
	var flag = document.getElementById("abc").checked;
	len = document.getElementById("no").value;
	for(i=0;i<len;i++)
	{
		document.getElementById("iId"+i).checked = flag;
	}  
}
/*
function isValidEmail(emailStr)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailStr))
	{
		return (true);
	}
	alert(JS_MSG_EMAIL);
	return (false);
}*/
function selectPassid(val_id, flag)
{
	var ilimit = document.frmlist.elements.length;
	var j=1;
	
	for(i=0; i<ilimit ; i++)
	{
	  	if(document.frmlist.elements[i].id == 'iId')
  		{
			if(j == val_id)
			{	
				document.frmlist.elements[i].checked = flag;
				break;
			}
			j++;
		}
	}
}

function showConverter()
{
	window.open("http://www.xe.com/ucc","mywindow","menubar=0,scrollbars=1,width=800,height=600");
	return false;
}
function setreset(frm,countryval,stateval,questionval)
{	
	frm.reset();
	countryobj=document.getElementById('vCountry');
	stateobj=document.getElementById('vState');
	questionobj=document.getElementById('vQuestion');
	
	setoptions(countryobj,countryval);
	setoptions(stateobj,stateval);
	setoptions(questionobj,questionval);
		
}
function setoptions(obj,val)
{
	len=obj.length;
 	for(i=0;i<len;i++)
	{
		if(obj.options[i].value!='')
		{		
			if(obj.options[i].value==val)
			{
				obj.options[i].selected=true;
			}	
		}								
	}
}		
function clearText(obj)
{
	if(obj){
		if(obj.name == "txtSearch"){
			if(obj.value == "By Keywords")
				obj.value = '';
			if(document.getElementById('MainoptionText'))
				document.getElementById('MainoptionText').checked=true;
			//if(document.getElementById('srchcondid_and'))
			//	document.getElementById('srchcondid_and').checked=true;
			
		}else if(obj.id == 'vUserName'){
			if(obj.value == "Username")
				obj.value = '';
		}else if(obj.id == 'vPassword'){
			if(obj.value == "Password")
				obj.value = '';
		}else if(obj.id == 'vUserNameCompany'){
			if(obj.value == "Username")
				obj.value = '';
		}else if(obj.id == 'vPasswordCompany'){
			if(obj.value == "Password")
				obj.value = '';
		}
	}
	
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function ValidateForm(mm,dd,yyyy){
	var dt=mm+"/"+dd+"/"+yyyy;
	var dtime=dt;
	var currdate = new Date();
	var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds()
	
	dtime=dtime+" "+hours+":"+minutes+":"+seconds;
	var userdate = new Date(dtime);
	if (Date.parse(currdate)<=Date.parse(userdate)){
			alert("Birthdate can be today’s date or earlier.");
			return false;
	}
	if (isDate(dt)==false){
		return false
	}
    return true
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	var alldate="";
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
	return true
}

function Clearall(theForm){
	var els = theForm.elements;
	if(theForm.name=="frmRegister")
	{
		if(theForm.vUserName)
			theForm.vUserName.value="";
		if(theForm.vPassword)
			theForm.vPassword.value="";
		if(theForm.cPassWord)
			theForm.cPassWord.value="";
		if(theForm.vQuestion)
			theForm.vQuestion.selectedIndex=0;
		if(theForm.vAnswer)
			theForm.vAnswer.value="";
		//For Company Start
		if(theForm.vName)
			theForm.vName.value="";
		//For Company End
		
		if(theForm.vImage)
			theForm.vImage.value="";
		//For Company Start
		if(theForm.vLogoImage)
			theForm.vLogoImage.value=" ";
		//For Company End
		
		if(theForm.vPrefix)
			theForm.vPrefix.selectedIndex=0;
		
		//For Company Start
		if(theForm.vContactFirst)
			theForm.vContactFirst.value="";
		if(theForm.vContactLast)
			theForm.vContactLast.value="";
		//For Company End
		
		if(theForm.vFirstName)
			theForm.vFirstName.value="";
		if(theForm.vLastName)
			theForm.vLastName.value="";
		if(theForm.dDay)
			theForm.dDay.selectedIndex=0;
		if(theForm.dMonth)
			theForm.dMonth.selectedIndex=0;
		if(theForm.dYear)
			theForm.dYear.selectedIndex=0;
		
		if(theForm.vCountry)
			theForm.vCountry.selectedIndex=0;
		if(theForm.vFindsite)
			theForm.vFindsite.selectedIndex=0;
		if(theForm.vAddress)
			theForm.vAddress.value="";
		if(theForm.vState)
			theForm.vState.selectedIndex=0;
		if(theForm.vCity)
			theForm.vCity.value="";
		if(theForm.vZip)
			theForm.vZip.value="";
		if(theForm.vEmail)
			theForm.vEmail.value="";
		if(theForm.cEmail)
			theForm.cEmail.value="";
		if(theForm.vPhone)
			theForm.vPhone.value="";
		if(theForm.vMoblie)
			theForm.vMoblie.value="";
		if(theForm.vWebsite)
			theForm.vWebsite.value="";
	}
	if(theForm.name=="frmcat")
	{
		if(theForm.eRepType)
			theForm.eRepType.selectedIndex=0;
		if(theForm.iNoOfSalesRep)
			theForm.iNoOfSalesRep.value="";
		if(theForm.iExperienceId)
			theForm.iExperienceId.selectedIndex=0;
		if(theForm.iMonthlySalesId)
			theForm.iMonthlySalesId.selectedIndex=0;
		if(theForm.eEducation)
			theForm.eEducation.selectedIndex=0;
		if(theForm.tProductlines)
			theForm.tProductlines.value="";
		if(theForm.tProducts)
			theForm.tProducts.value="";
		if(theForm.iAnnualSalesId)
			theForm.iAnnualSalesId.selectedIndex=0;
		if(theForm.tExpectedWork)
			theForm.tExpectedWork.value="";
			
		if(theForm.all_cat_str)
		{
			var cat_str=theForm.all_cat_str.value  
			
			par_cat_arr=cat_str.split(",");
			for (var i=0;i<theForm.elements.length;i++){
				var e = theForm.elements[i];
				if( e.type=='checkbox'  && par_cat_arr.in_array(e.id)  ) {
					theForm.category.checked=false;
					e.checked = false;
				}
			}
			var cate_arr = new Array();
			if(document.getElementById("parent_cate_id_str").value!="")
			cate_arr = document.getElementById("parent_cate_id_str").value.toString().split(',');
			for(var i = 0 ; i < cate_arr.length ; i++)
			{
				expendCat(cate_arr[i]);
			}	
		}
if(theForm.BDtotrec.value!='')
{
  tot_terrBD=theForm.BDtotrec.value
   for(r=0;r<tot_terrBD;r++)
	     {
	         
		  document.getElementById('BDterritory'+r).checked=false;     
    	}
  document.getElementById('check_BD').checked=false;
  document.getElementById('showstateBD').style.display='none';
  
}
if(theForm.INtotrec.value!='')
{
  tot_terrIN=theForm.INtotrec.value
   for(r=0;r<tot_terrIN;r++)
	     {
	         
		  document.getElementById('INterritory'+r).checked=false;     
    	}
  document.getElementById('check_IN').checked=false;
  document.getElementById('showstateIN').style.display='none';
}
if(theForm.NPtotrec.value!='')
{
  tot_terrNP=theForm.NPtotrec.value
   for(r=0;r<tot_terrNP;r++)
	     {
	         
		  document.getElementById('NPterritory'+r).checked=false;     
    	}
  document.getElementById('check_NP').checked=false;
  document.getElementById('showstateNP').style.display='none';
}
if(theForm.LKtotrec.value!='')
{
  tot_terrLK=theForm.LKtotrec.value
   for(r=0;r<tot_terrLK;r++)
	     {
	         
		  document.getElementById('LKterritory'+r).checked=false;     
    	}
  document.getElementById('check_LK').checked=false;
  document.getElementById('showstateLK').style.display='none';
}
if(theForm.PKtotrec.value!='')
{
  tot_terrPK=theForm.PKtotrec.value
  for(r=0;r<tot_terrPK;r++)
	     {
	         
		  document.getElementById('PKterritory'+r).checked=false;     
    	}
  document.getElementById('check_PK').checked=false;
  document.getElementById('showstatePK').style.display='none';
}
 
	/*	var all_terr=document.getElementById("all_tett").value
  		var tett_arr=all_terr.split(",");
  		document.frmcat.terr.checked=false;
  		rs = false;
  		for(j=0;j<tett_arr.length;j++){
    		var na='territory'+j;
     		document.getElementById('territory'+j).checked=rs;
  		}*/

		if(theForm.vCatOther)
			theForm.vCatOther.checked=false;
		if(theForm.vCatOtherTxt)
			theForm.vCatOtherTxt.value="";
		if(theForm.tCities)
			theForm.tCities.value="";
		if(theForm.tTarget)
			theForm.tTarget.value="";
		if(theForm.eComp)
			theForm.eComp.selectedIndex="-1";
		if(theForm.vKeyword)
			theForm.vKeyword.value="";
		if(theForm.vKeyWord)
			theForm.vKeyWord.value="";
		if(theForm.eAlert)
			theForm.eAlert.checked=false;
		
	}
	return false;
	/*for(i=0; i<els.length; i++){ 
		switch(els[i].type){
			case "select-one" :
					els[i].options[els[i].selectedIndex].value == ""
					els[i].selectedIndex = 0;
				break;

			case "text":
			case "hidden":
			case "textarea":
					els[i].value= "";
				break;
			case "checkbox":
					els[i].checked = true;
				break;
			case "radio":
					els[i].checked = true;
				break;
		}
	}*/
}
function getterrcount(tot_terr,ID)
  {
	  alert(tot_terr);
   
	     for(r=0;r<tot_terr;r++)
	     {
	         
		  document.getElementById(ID+'territory'+r).checked=false;
		  alert('yes');
		     
    	}
  }

function numberFormat (context) {
var val = (context == null) ? new Number(this) : Math.abs(this);
var arr = val.round(2).toFixed(2).split('.');
arr[0] = (val < 0 ? '-' : '') + String.leftPad((val < 0 ? arr[0].substring(1) : arr[0]), 1, '0');
arr[0] = Number.injectIntoFormat(arr[0].reverse(), '0', true).reverse();
arr[1] = Number.injectIntoFormat(arr[1], '00', false);
return arr.join('.');
}

