/* Common Javascript Functions Start */
function Trim(nStr){return nStr.replace(/(^\s*)|(\s*$)/g, "");}
function isNull(obj,msg){
	if(msg!="Password")
		obj1=Trim(obj.value);
	else
		obj1=obj.value;
	if (obj1==""){
		alert("Please enter the " +msg);
		obj.focus();
		return true;
	}else
		return false;
}
function isLen(obj,siz,msg){
	if(msg!="Password")
		obj1=Trim(obj.value);
	else
		obj1=obj.value;
	if(obj1!=""){
		var strLen=obj.value;
		if(strLen.length < siz){
			alert(msg+" should be atleast " + siz + " characters");
			obj.focus();
			return true;  
		} 
	}else
		return false;
}
function isNullBrowse(obj,msg){
	if(msg!="Password")
		obj1=Trim(obj.value);
	else
		obj1=obj.value;
	if (obj1==""){
		alert("Please choose the " +msg);
		obj.focus();
		return true;
	}else
		return false;
}
function isSame(obj1,obj2,msg1,msg2){
	if((Trim(obj1.value))==(Trim(obj2.value))){
		alert(msg1+" is matched with the "+msg2);
		obj2.focus();
		return true;
	}else
		return false;
}	
function isNotSame(obj1,obj2,msg1,msg2){
	if((Trim(obj1.value))!=(Trim(obj2.value))){
		alert(msg1+" and "+msg2+" does not match");
		obj2.focus();
		return true;
	}else
		return false;
}	
function isCorrect(obj1,obj2,msg1,msg2){
	if((Trim(obj1.value)) >= (Trim(obj2.value))){
		alert(msg1+" should be less than "+msg2);
		obj2.focus();
		return true;
	}else
		return false;
}	
function isTxtareaNull(obj,msg){
	if(Trim(obj.innerText) == ""){
		alert("Please enter " + msg);
		obj.focus();
		return true;
	}else
		return false;
}
function isTxtareaLen(obj,msg){
	if(obj.innerHTML.length > 255){
		alert("Please enter below 256 characters in " + msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notEmail(obj,msg){
	var exp=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	if (!exp.test(obj.value)){
		alert("Please enter valid "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notZipcode(obj,msg){
	exp = /[a-zA-Z|\d]-{1}/;
	if (!exp.test(obj.value)){
		alert("Please enter valid "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function fnTel(obj,msg){
	//exp = /^\(?[0-9+ -]*$/;
	var ob = obj.value.replace(/\./g,'');
	exp = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/;
	if (!exp.test(ob)){
		alert("Please enter valid "+msg);
		obj.focus();
		return true;
	}else{
		return false;
	}
}
function notChecked(obj,msg){
	checked = false;
	if(obj.length){
		for(i=0;i<obj.length;i++){
			if(obj[i].checked){
				checked = true;break;
			}
		}
	}else if(obj.checked)
		checked = true;
	if(!(checked)){
		alert("Please select the "+msg);
		if(obj.length)
			obj[0].focus();
		else
			obj.focus();
		return true;
	}
}
function isNullImage(obj,msg){
	if(msg!="Password")
		obj1=Trim(obj.value);
	else
		obj1=obj.value;
	if (obj1==""){
		alert("Please choose the " +msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notSelected(obj,msg){
	if (obj.options[obj.selectedIndex].value == ""){
		alert("Please select the "+ msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notImageFile(obj,msg){
	var exp = /^.+\.(jpg|gif|jpeg|JPG|JPEG|GIF|png|PNG)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose jpg or gif file for "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notImageFlashFile(obj,msg){
	var exp = /^.+\.(jpg|gif|jpeg|swf|JPG|JPEG|GIF|SWF|png|PNG)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose jpg or gif or swf file for "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notJpgFile(obj,msg){
	var exp = /^.+\.(jpg|jpeg|JPG|JPEG)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose jpg file for "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notDocFile(obj,msg){
	if(Trim(obj.value)!=""){
		var exp = /^.+\.(DOC|doc|TXT|txt)$/;
		if (!exp.test((obj.value).toLowerCase())){
			alert("Please choose doc or txt file for "+msg);
			obj.value="";
			obj.focus();
			return true;
		}else
			return false;	
	}else
		return false;
}
function notPdfDocFile(obj,msg){
	var exp = /^.+\.(pdf|doc|PDF|DOC)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose pdf or doc file for "+msg);
		obj.value="";
		obj.focus();
		return true;
	}else
		return false;
}
function notPdfFile(obj,msg){
	var exp = /^.+\.(pdf|PDF)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose pdf file for "+msg);
		obj.value="";
		obj.focus();
		return true;
	}else
		return false;
}
function notPdfZipRarFile(obj,msg){
	var exp = /^.+\.(pdf|PDF|zip|rar|ZIP|RAR)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose pdf file for "+msg);
		obj.value="";
		obj.focus();
		return true;
	}else
		return false;
}
function notPrice(obj,msg){
	exp = /^[\d]*[\.]{0,1}[\d]{1,2}$/;
	if (!exp.test(obj.value)){
		alert("Please enter valid "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function fnChkNum(obj,msg){
	exp = /^[\d]/;
	if (!exp.test(obj.value)){
		alert("Please enter only numeric values in "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function fnChkAlpha(obj,msg){
	exp = (/(^([a-z]|[A-Z]|["."]|[\s])*$)/);
	if (!exp.test(obj.value))	{
		alert("Please enter only alphabets in "+msg);
		obj.focus();
		return true;
	}else
		return false;
}	
function fnChkAlphaNum(obj,msg){
	exp = (/(^([a-z]|[A-Z]|[0-9])*$)/);
	if (!exp.test(obj.value)){
		alert("Please enter only alphanumeric in "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function fnChkNumeric(obj,msg){
	exp = (/(^([0-9])*$)/);
	if (!exp.test(obj.value)){
		alert("Please enter only numeric in "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function fnChkAlphaNumeric(obj,msg){
	var alpha = /[a-zA-Z|]/;
	var Num = /[\d]/;
	if (!(Alpha.test(obj.value) && Num.test(obj.value))){
		alert("Please enter only alphanumeric in "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function isEditorNull(obj,msg){
	strTmp = obj.value;
	StrContent=strTmp.split("<BODY>");
	StrContent=StrContent[1];
	StrContent=StrContent.split("</BODY>");
	StrContent=StrContent[0];
	strLength=StrContent.length;
	if (strLength==0){
		alert (msg);
		return true;
	}else
		return false;
}
function fnChkFolderName(){
	if(((window.event.keyCode < 48) || (window.event.keyCode > 57)) && ((window.event.keyCode < 65) || (window.event.keyCode > 90)) && ((window.event.keyCode < 97) || (window.event.keyCode > 122)) && (window.event.keyCode != 95)){
		alert("Only Alphabets(A-Z, a-z), Numbers(0-9) and Underscore(_) are allowed");
		window.event.keyCode = 0;
		return true;
	}
}
function fnselectall(){
	obj = document.thisForm.elements['chkSelect[]'];
	chkSelectAll = document.thisForm.chkSelectAll;
	if(obj.length){
		if(chkSelectAll.checked == true){
			for(i=0;i<obj.length;i++){
				if(obj[i].checked == false){
					obj[i].checked = true;
				}
			}
		}else{
			for(i=0;i<obj.length;i++){
				if(obj[i].checked == true){
					obj[i].checked = false;
				}
			}
		}
	}else{
		if(chkSelectAll.checked == true){
			obj.checked = true;
		}else{
			obj.checked = false;
		}
	}		
}
function fnselect(){
	obj = document.thisForm.elements['chkSelect[]'];
	chkSelectAll = document.thisForm.chkSelectAll;
	if(obj.length){
		chkSelectAll.checked = true;
		for(i=0;i<obj.length;i++){
			if(obj[i].checked == false){
				chkSelectAll.checked = false;
				break;
			}
		}
	}else{
		if(obj.checked == true){
			chkSelectAll.checked = true;
		}else{
			chkSelectAll.checked = false;
		}
	}	
}
/* Common Javascript Functions Ends */
function fnChangeStatus(arg,page_name,type){
	if(notChecked(document.thisForm.elements['chkSelect[]'],type+' to '+arg)){ return false };
	if(confirm("Are you sure, do you want to "+arg+" the selected "+type+"?")){
		document.thisForm.action=page_name+"?action="+arg;
		document.thisForm.submit();
	}	
}
function fnDelete(arg,page_name,type){
	if(notChecked(document.thisForm.elements["chkSelect[]"],type+' to '+arg)) return false;
	if(confirm("Are you sure, do you want to "+arg+" the selected "+type+"?")){
		document.thisForm.action=page_name+"?action="+arg;
		document.thisForm.submit();
	}
}
/* Login Validation Starts */
function fnValidateLogin(){
	if (isNull(document.frmUserLogin.txtUserName,"username")){ return false; }
	if (isNull(document.frmUserLogin.txtPassword,"password")){ return false; }
}
/* Login Validation Ends */
function fnValidateFreeSignup(){
	if (isNull(document.thisForm.txtName,"name")){ return false; }
	if (isNull(document.thisForm.txtUserName,"e-mail")){ return false; }
	if (notEmail(document.thisForm.txtUserName,"e-mail")){ return false; }
	if (isNull(document.thisForm.txtPassword,"password")){ return false; }
	var st=document.thisForm.txtPassword.value;
	if(st.length < 5 ){
		alert("Password should be more than 4 character");
		document.thisForm.txtPassword.focus();
		return false;
	}
	if(st.length > 8 ){
		alert("Password should not be more than 8 character");
		document.thisForm.txtPassword.focus();
		return false;
	}
	if(isNull(document.thisForm.txtConfirmPassword,"confirm password")){ return false;}
	if(isNotSame(document.thisForm.txtPassword,document.thisForm.txtConfirmPassword,"password","confirm password")){ return false;}
}
function fnValidatePremiumSignup(){
	if (isNull(document.thisForm.txtName,"name")){ return false; }
	if (isNull(document.thisForm.txtUserName,"e-mail")){ return false; }
	if (notEmail(document.thisForm.txtUserName,"e-mail")){ return false; }
	if (isNull(document.thisForm.txtPassword,"password")){ return false; }
	var st=document.thisForm.txtPassword.value;
	if(st.length < 5 ){
		alert("Password should be more than 4 character");
		document.thisForm.txtPassword.focus();
		return false;
	}
	if(st.length > 8 ){
		alert("Password should not be more than 8 character");
		document.thisForm.txtPassword.focus();
		return false;
	}
	if(isNull(document.thisForm.txtConfirmPassword,"confirm password")){ return false;}
	if(isNotSame(document.thisForm.txtPassword,document.thisForm.txtConfirmPassword,"password","confirm password")){ return false;}
	if(notSelected(document.thisForm.cmbPremiumPlan,"premium plan")){ return false;} 	
}
function fnValidateForgotPassword(){
	if (isNull(document.thisForm.txtUserName,"username")){ return false; }
}
function fnValidateReportAbuse(){
	if (isNull(document.thisForm.txtName,"name")){ return false; }
	if (isNull(document.thisForm.txtEmail,"e-mail")){ return false; }
	if (notEmail(document.thisForm.txtEmail,"e-mail")){ return false; }
	if(Trim(document.thisForm.txtContactNo.value) != ""){
		if (fnTel(document.thisForm.txtContactNo,"contact no")){ return false; }
	}
	if (isNull(document.thisForm.txtMessage,"message")){ return false; }
}
function fnValidateProfile(){
	if (isNull(document.thisForm.txtName,"name")){ return false; }
	if (isNull(document.thisForm.txtPassword,"password")){ return false; }
	var st=document.thisForm.txtPassword.value;
	if(st.length < 5 ){
		alert("Password should be more than 4 character");
		document.thisForm.txtPassword.focus();
		return false;
	}
	if(st.length > 8 ){
		alert("Password should not be more than 8 character");
		document.thisForm.txtPassword.focus();
		return false;
	}
	
}
