// 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 isBlank(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
	{
		document.getElementById(divname).innerHTML= "";
		document.getElementById(divname).style.display="none";

	}
}

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 ) 
	{ 
		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="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 chk_mobile_number()
{
	var mobnum;
	mobnum = document.Frm_Create_topic.txt_mobnos.value;
	
	mobnumarr = mobnum.split(",");
	mobnumlen = mobnumarr.length;
	
	var mobStr = /^[0-9 12]/;
	
		for(i=0;i<mobnumlen;i++)
		{
			if(mobnumarr[i] == '')
			{
				alert("Please enter the phone number correctly");
				return false;
			}
			else if(isNaN(mobnumarr[i]))
			{
				alert("Characters are not allowed, please enter valid numeric mobile number.");
				return false;
			}
			else if(mobnumarr[i].length<12)
			{
				alert("Mobile number should be 12 digit.");
				return false;	
			}
			else if(mobnumarr[i].substring(0,2) !="91")
			{
				alert("Mobile number should start with 91.");
				return false;
			}
			
		}


}

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 conDel(action,tmp_frmName)
{
	var cnf;
	var frmName=eval("document."+tmp_frmName);
	var chkSel	= showcheck(frmName);
	if(chkSel == "Y")
	{
			
		if(action == "Del")
		{
			cnf=confirm("Do you want to delete the selected record(s)!");
			if(cnf)
			{
				frmName.submit();
				//frmName.selAction.options[0].selected = true;
			}
			else
			{	
				return false;
			}//else
		
		}//if(action == "Del")
		frmName.submit();
	
	}
	else
	{
		frmName.selAction.options[0].selected = true;
		return false;
	}
}

function chkValidation(txtVal,msg,divname,tblName,fldName,fldValue,fldPart,flag,dbVal,siteURL)
{
    var frm_field_name = fldName;
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url = siteURL+"valid_page_name.php"+"?fName="+fldName+"&fval="+fldValue+"&tblName="+tblName+"&txtVal="+txtVal+"&part="+fldPart+"&f="+flag+"&dbVal="+dbVal+"&msg="+msg;
	//alert(url);
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			//alert(xmlHttp.responseText);
			if (xmlHttp.responseText != "") 
			{
				document.getElementById(divname).innerHTML= xmlHttp.responseText;
				document.getElementById(divname).style.display="block";
			}
			if(xmlHttp.responseText	== 0)
			{
				document.getElementById(divname).innerHTML="Please enter "+msg;
				document.getElementById(divname).style.display="block";
			}
			
			if(xmlHttp.responseText == 2 )
			{
				document.getElementById(divname).innerHTML="";
				document.getElementById(divname).style.display="none";
			}
		}
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

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 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 for check password
function valid_password(fldName,txtboxName,fldValue,divname,recId,confirmval)
{
	var frm_txtbox_name=eval(txtboxName);
	var frm_con_fld_name=eval(confirmval);
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return false;
	} 
	if(fldName=='oldpass')
	{
		var url="validate_change_pass.php"
		url=url+"?id="+recId
		url=url+"&fValue="+fldValue
		
		xmlHttp.onreadystatechange=function()
		{
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{
				if(xmlHttp.responseText==0)
				{
					document.getElementById(divname).innerHTML="Please enter the old password.";
					document.getElementById(divname).style.display="block";
				}
				else if(xmlHttp.responseText==1)
				{
					document.getElementById(divname).innerHTML="Invalid password.";
					document.getElementById(divname).style.display="block";
				}
				else
				{
					document.getElementById(divname).innerHTML="";
					document.getElementById(divname).style.display="none";
				}
			}
		}
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}
	else
	{
		if(fldName=='newpass')
		{
			if(frm_txtbox_name.value=="")
			{
				document.getElementById(divname).innerHTML="Please enter the new password.";
				document.getElementById(divname).style.display="block";				
			}
			else if(frm_txtbox_name.value==frm_con_fld_name.value)
			{
				document.getElementById(divname).innerHTML="New password should be different.";
				document.getElementById(divname).style.display="block";
			}
			else
			{
				document.getElementById(divname).innerHTML="";
				document.getElementById(divname).style.display="none";
			}
		}
		if(fldName=='conpass')
		{
			if(frm_txtbox_name.value=="")
			{
				document.getElementById(divname).innerHTML="Please enter the confirm password.";
				document.getElementById(divname).style.display="block";
			}
			else if(frm_txtbox_name.value!=frm_con_fld_name)
			{
				document.getElementById(divname).innerHTML="Password mismatch.";
				document.getElementById(divname).style.display="block";
			}
			else
			{
				
				document.getElementById(divname).innerHTML="";
				document.getElementById(divname).style.display="none";
			}
		}
	}
}