//***************function to check empty textbox***************//

whitespace = "\t \n\r";
function isEmptyString(s)
{
   	var i;
  	if((s == null) || (s.length == 0)) return true;
  	for(i=0;i < s.length;i++)
  	{
  		var currchar = s.charAt(i);
  		if(whitespace.indexOf(currchar) == -1) return false;
  	}
      return true;
}
//----------**end of function to check empty textbox**----------//



//***************function to check numeric value***************//
function isNotNumeric(s)
{
  	if(isNaN(s))
  	{
  		return(true);
  	}
  	return(false);
}
//----------**end of function to check numeric value**----------//



//***************function to validate Email***************//
function isEmail(n)
{
		if ((n==null) || (n.length==0))
		{
			return true;
		}
		if (isEmptyString(n)) return false;
		var i=1;
		var nLength=n.length;
		while((parseInt(i) < parseInt(nLength)) && (n.charAt(parseInt(i)) != '@'))
		{
			i++;
		}
		if ((parseInt(i) >= parseInt(nLength)) || (n.charAt(i)!="@"))
		{
			return false;	
		}	
		else i+=2;
		while((i<nLength) && (n.charAt(i)!="."))
		{
			i++;
		}
		if ((i>=nLength-1) || (n.charAt(i)!="."))
		{
			return false;	
		}	
		else return true;		
}
//----------**end of function to validate Email**----------//
//----------**end of function for validate date in a single textbox**----------//
function OpenNewWindow(w,h,mypage,newwinanme)
  	{
	  	//if (!validateMode()) return;
	  	var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no';
		imgwin = window.open(mypage, newwinanme, winprops);
		if (parseInt(navigator.appVersion) >= 4) {imgwin.window.focus();}
}
//-------**********Open New Pop Up Window********--------------
function OpenNewWindowwithscroll(w,h,mypage,newwinanme)
{
	  	var winl = (screen.width - w)/2;
		var wint = 2;
		winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no';
		imgwin = window.open(mypage, newwinanme, winprops);
		if (parseInt(navigator.appVersion) >= 4) {imgwin.window.focus();}
}
function OpenNewWindowwithtoolbar(w,h,mypage,newwinanme)
{
	  	var winl = (screen.width - w)/2;
		var wint = 2;
		winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,directories=yes,status=yes';
		imgwin = window.open(mypage, newwinanme, winprops);
		if (parseInt(navigator.appVersion) >= 4) {imgwin.window.focus();}
}
//--------------******file extensions to be uploaded*******--------------//
extArray = new Array(".gif",".jpg",".jpeg",".jpe");
function Allowed_Uploaded_Files(File_Value)
{
	allowSubmit = false;
	if (!File_Value)
	{
		return true;
	}
	while (File_Value.indexOf("\\") != -1)
	{
		File_Value = File_Value.slice(File_Value.indexOf("\\") + 1);
	}
	ext = File_Value.slice(File_Value.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++)
	{
		if (extArray[i] == ext)
		{
			allowSubmit = true;
			break;
		}
	}
	if (allowSubmit)
	{
		return true;
	}
	else
	{
		return false;
	}
}
function Select_Delect_All(total_records_viewed)
{
	for(i=0;i<total_records_viewed;i=i+1)
	{
		if(document.frm_1.chk_SD.checked==true)
		{
			document.frm_1.elements["chk_1["+i+"]"].checked=true;
		}
		else
		{
			document.frm_1.elements["chk_1["+i+"]"].checked=false;
		}
	}
}
function Select_Delect_feature(total_records_viewed)
{
	for(i=0;i<total_records_viewed;i=i+1)
	{
		if(document.frm_1.chk_feature.checked==true)
		{
			document.frm_1.elements["chk_2["+i+"]"].checked=true;
		}
		else
		{
			document.frm_1.elements["chk_2["+i+"]"].checked=false;
		}
	}
}
function confdel(myformname)
{
	var fl = 0;
	for(i = 0; i < (document.forms[myformname].elements.length); i++)
	{
		if((document.forms[myformname].elements[i].type=="checkbox") && (document.forms[myformname].elements[i].checked==true))
		{
			fl = 1;
			break;
		}
	}
	if(fl == 1)
	{
		if(confirm("Are you sure you want to Delete?"))
		{
			fl = 1;
		}
		else
		{
			fl = 0;
		}
	}
	else
	{
		alert("Nothing to Delete.");
		fl = 0;
	}
	if(fl == 1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function PostSearchForm()
{
		if(isEmptyString(document.frm_1.uname.value.toString()))
	{
		alert("Please Enter User Name");
		document.frm_1.uname.value="";
		document.frm_1.uname.focus();
		return false;
	}
   	if (isEmptyString(document.frm_1.upass1.value.toString()))
	{
		alert("Please Enter Your password");
		document.frm_1.upass1.value="";
		document.frm_1.upass1.focus();
		return false;
	}
	if (isEmptyString(document.frm_1.upass2.value.toString()))
	{
		alert("Please Enter Your Confirm password");
		document.frm_1.upass2.value="";
		document.frm_1.upass2.focus();
		return false;
	}
	if (document.frm_1.upass1.value!=document.frm_1.upass2.value)
	{
		alert("Your new password and confirm new password should be same");
		document.frm_1.upass2.focus();
		return false;
	}

	if(isEmptyString(document.frm_1.ufname.value.toString()))
	{
		alert("Please Enter FirstName");
		document.frm_1.ufname.value="";
		document.frm_1.ufname.focus();
		return false;
	}
		if(isEmptyString(document.frm_1.ulname.value.toString()))
	{
		alert("Please Enter LastName");
		document.frm_1.ulname.value="";
		document.frm_1.ulname.focus();
		return false;
	}
	if(isEmptyString(document.frm_1.ucomname.value.toString()))
	{
		alert("Please Enter CompanyName");
		document.frm_1.ucomname.value="";
		document.frm_1.ucomname.focus();
		return false;
	}
	if(isEmptyString(document.frm_1.uadd1.value.toString()))
	{
		alert("Please Enter Address");
		document.frm_1.uadd1.value="";
		document.frm_1.uadd1.focus();
		return false;
	}
	if(isEmptyString(document.frm_1.uctname.value.toString()))
	{
		alert("Please Enter City");
		document.frm_1.uctname.value="";
		document.frm_1.uctname.focus();
		return false;
	}
	if(isEmptyString(document.frm_1.ustname.value.toString()))
	{
		alert("Please Enter State");
		document.frm_1.ustname.value="";
		document.frm_1.ustname.focus();
		return false;
	}
	var a;
	a=document.frm_1.elements["ucontname"].value
	if(a=="")
	{
		alert("Please Enter Country");
		document.frm_1.ucontname.value="";
		document.frm_1.ucontname.focus();
		return false;
	}
	if(isEmptyString(document.frm_1.uzcode.value.toString()))
	{
		alert("Please Enter Zip Code");
		document.frm_1.uzcode.value="";
		document.frm_1.uzcode.focus();
		return false;
	}
	
	if(isEmptyString(document.frm_1.uwph.value.toString()))
	{
		alert("Please Enter Work Phone");
		document.frm_1.uwph.value="";
		document.frm_1.uwph.focus();
		return false;
	}
	if(isNotNumeric(document.frm_1.uwph.value))
	{
		alert("Please Enter Work Phone in numeric");
		document.frm_1.uwph.value="";
		document.frm_1.uwph.focus();
		return false;
	}
	if(isEmptyString(document.frm_1.umail.value.toString()))
	{
		alert("Please Enter Email");
		document.frm_1.umail.value="";
		document.frm_1.umail.focus();
		return false;
	}
	if(!isEmail(document.frm_1.umail.value.toString()))
	{
		alert("Please Enter Email in Correct Format");
		//document.frm_1.email.value="";
		document.frm_1.umail.focus();
		return false;
	}
}
//---------------------------------------------------//
function editPostSearchForm()
{
	if(isEmptyString(document.frm_1.ufname.value.toString()))
	{
		alert("Please Enter FirstName");
		document.frm_1.ufname.value="";
		document.frm_1.ufname.focus();
		return false;
	}
		if(isEmptyString(document.frm_1.ulname.value.toString()))
	{
		alert("Please Enter LastName");
		document.frm_1.ulname.value="";
		document.frm_1.ulname.focus();
		return false;
	}
	if(isEmptyString(document.frm_1.ucomname.value.toString()))
	{
		alert("Please Enter CompanyName");
		document.frm_1.ucomname.value="";
		document.frm_1.ucomname.focus();
		return false;
	}
	if(isEmptyString(document.frm_1.uadd1.value.toString()))
	{
		alert("Please Enter Address");
		document.frm_1.uadd1.value="";
		document.frm_1.uadd1.focus();
		return false;
	}
	if(isEmptyString(document.frm_1.uctname.value.toString()))
	{
		alert("Please Enter City");
		document.frm_1.uctname.value="";
		document.frm_1.uctname.focus();
		return false;
	}
	if(isEmptyString(document.frm_1.ustname.value.toString()))
	{
		alert("Please Enter State");
		document.frm_1.ustname.value="";
		document.frm_1.ustname.focus();
		return false;
	}
	var a;
	a=document.frm_1.elements["ucontname"].value
	if(a=="")
	{
		alert("Please Enter Country");
		document.frm_1.ucontname.value="";
		document.frm_1.ucontname.focus();
		return false;
	}
	if(isEmptyString(document.frm_1.uzcode.value.toString()))
	{
		alert("Please Enter Zip Code");
		document.frm_1.uzcode.value="";
		document.frm_1.uzcode.focus();
		return false;
	}
	
	if(isEmptyString(document.frm_1.uwph.value.toString()))
	{
		alert("Please Enter Work Phone");
		document.frm_1.uwph.value="";
		document.frm_1.uwph.focus();
		return false;
	}
	if(isNotNumeric(document.frm_1.uwph.value))
	{
		alert("Please Enter Work Phone in numeric");
		document.frm_1.uwph.value="";
		document.frm_1.uwph.focus();
		return false;
	}
	if(isEmptyString(document.frm_1.umail.value.toString()))
	{
		alert("Please Enter Email");
		document.frm_1.umail.value="";
		document.frm_1.umail.focus();
		return false;
	}
	if(!isEmail(document.frm_1.umail.value.toString()))
	{
		alert("Please Enter Email in Correct Format");
		//document.frm_1.email.value="";
		document.frm_1.umail.focus();
		return false;
	}
}
//----------------------------//
function addPostSearchForm()
{
	
	if(isEmptyString(document.frm_1.cname.value.toString()))
	{
		alert("Please Enter Company Name");
		document.frm_1.cname.value="";
		document.frm_1.cname.focus();
		return false;
	}
	if(isEmptyString(document.frm_1.pname.value.toString()))
	{
		alert("Please Enter Product Name");
		document.frm_1.pname.value="";
		document.frm_1.pname.focus();
		return false;
	}
	

}

function forgotpassword(mypage,myname,w,h,scrollyesno)
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollyesno+',resizable'
	win = window.open(mypage, myname, winprops)
	
}
function loginForm()
{
		if(isEmptyString(document.form1.username.value.toString()))
	{
		alert("Please Enter User Name");
		document.form1.username.value="";
		document.form1.username.focus();
		return false;
	}
   	if (isEmptyString(document.form1.password.value.toString()))
	{
		alert("Please Enter Your password");
		document.form1.password.value="";
		document.form1.password.focus();
		return false;
	}
}