// JavaScript Document

// JavaScript Document


var http;
function ajaxDiv(url,div,func){
	if(window.XMLHttpRequest){
		http=new XMLHttpRequest();
	}else if(window.ActiveXObject){
		http=new ActiveXObject('msxml2.XMLHTTP');
//		new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(http){
		http.open('get',url,true);
		http.send(null);
		http.onreadystatechange=function(){
			if(http.readyState==4){
				if(http.status==200){
					var res=http.responseText;
					if(func != null){
						eval(func);
					}else if(div != null){
						document.getElementById(div).innerHTML=res;
					}
//					return res;
				}
			}
		}
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////

function validate(frm,func){
	for(i=0;i<frm.elements.length;i++){
		if(frm.elements[i].type=='text' || frm.elements[i].type=='password' || frm.elements[i].type=='textarea'){
			
			if(frm.elements[i].name=='email'){
				if(valid_email(frm.elements[i].value)){alert("Please Enter valid "+frm.elements[i].name);frm.elements[i].select();return false}
			}else if(frm.elements[i].value.match(/[a-zA-Z0-1]/)==null){
				alert("Please Enter "+frm.elements[i].name);
				frm.elements[i].select();
				return false;
			}
		}
	}
	if(func != null){eval(func);return false;}else{return true;}
}


function imageValidate(frm){
	var flag=true;
	for(i=0;i<frm.elements.length;i++){
		if(frm.elements[i].type=='text' || frm.elements[i].type=='password' || frm.elements[i].type=='textarea'){
			
			if(frm.elements[i].name=='email'){
				if(valid_email(frm.elements[i].value)){
					flag=false;
					alert("Please Enter valid "+frm.elements[i].name);
					frm.elements[i].select();
				}
			}else if(frm.elements[i].value.match(/[a-zA-Z0-1]/)==null){
				flag=false;
				alert("Please Enter "+frm.elements[i].name);
				frm.elements[i].select();
			}
		}
	}
	if(flag){
		frm.submit();
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////

function valid_email(eml)
{
	//declare the required variables
	var mint_len;
	var mstr_eml=eml;
	var mint_at=0;
	var mint_atnum=0;
	var mint_dot=0;
	var mint_dotnum=0;

	mint_len = eml.length; //takes the length of the email address entered
	//checking for the symbol single quote. If found replace it with its html code
	if (mstr_eml.indexOf("'")!=-1)
	{	
		mstr_eml=mstr_eml.replace("'","'");
	}
	//checking for the (@) & (.) symbol
	for(var iloop=0;iloop<mint_len;iloop++)
	{
		if(mstr_eml.charAt(iloop)=="@")
		{
			mint_at=iloop+1;
			mint_atnum=mint_atnum+1;
		}
		if(mstr_eml.charAt(iloop)==".")
		{
			mint_dot=iloop+1;
			mint_dotnum=mint_dotnum+1;
		}
	}
	//if nothing entered in the field
	if (mstr_eml=="")
	{
		return true;
	}
	//if @ entered more than once & dot (.) entered more than 4 times
	else if((mint_atnum!=1)||(mint_dotnum>4)||((mint_dot-mint_at)<2)||((mint_len-mint_dot)<2)||(mint_at<3))
	{
		return true;
	}
	//if any blank space is entered in the email address
	else if (mstr_eml.indexOf(" ")!=-1)
	{
		return true;
	}
	return false;
}


function limitText(limitField, limitCount, limitNum){
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}


function openWindow(url,width,height,resize,scrl) {
	width=(width==null || width=='')?400:width;
	height=(height==null || height=='')?300:height;
	resize=(resize==null || resize=='')?'yes':resize;
	scrl=(scrl==null || scrl=='')?'yes':scrl;
	window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrl+',resizable='+resize+',copyhistory=no,width='+width+',height='+height+',screenX=150,screenY=150,top=150,left=150')
}

function del(frm_id,id,msg){
	if(msg==null){msg='Are you sure to delete';}
	if(confirm(msg)==true){
		document.getElementById(frm_id).submit();
	}
}


function conf(url,msg){
	if(confirm(msg)==true){
		window.location=url;
	}
}

function validate_password(frm){
	if(frm.old_password.value == ''){
		alert("Old password can not be empty");
		frm.old_password.focus();
		return false;
	}else if(frm.old_password.value.match(/[a-zA-Z0-9]{8}/)==null){
		alert("Old password must be more than 8 characters");
		frm.old_password.focus();
		return false;
	}else if(frm.password.value == ''){
		alert("Password can not be empty");
		frm.password.focus();
		return false;
	}else if(frm.password.value.match(/[a-zA-Z0-9]{8}/)==null){
		alert("Password must be more than 8 characters");
		frm.password.focus();
		return false;
	}else if(frm.password1.value == ''){
		alert("Retype Password can not be empty");
		frm.password1.focus();
		return false;
	}else if(frm.password1.value.match(/[a-zA-Z0-9]{8}/)==null){
		alert("Retype Password must be more than 8 characters");
		frm.password1.focus();
		return false;
	}else if(frm.password.value != frm.password1.value){
		alert("password and Retype password should be same");
		frm.password1.focus();
		return false;
	}else{
		return true;
	}
}

function checkBlankField (txt)
{
	var mint_txt = txt.length;
	var mstr_txt = txt;
	var mint_count = 0;
	for (var iloop = 0; iloop<mint_txt; iloop++)
	{
        if (mstr_txt.charAt(iloop) == " ")
        {
           mint_count = mint_count+1;
        }
	}    
// if nothing entered in the field
	if (txt == "")
   	{
		return false;
	}
	else if (mint_count == mint_txt)
	{
		return false;
	}
	return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////

function validate_page(frm_name){
	var frm=document.getElementById(frm_name);
	if(checkBlankField(frm.page_title.value)==false){
		alert("Page title can not be empty");
		frm.page_title.select();
	}else{
		frm.submit();
	}
}


function manage_div(no,total,val){
	if(total > 1){
		for(i=0;i<total;i++){
			document.getElementById('head_'+i).className='overview_other_tab';
			document.getElementById('body_'+i).style.display='none';
		}
		document.getElementById('head_'+no).className='overview_text_btn';
		document.getElementById('body_'+no).style.display='block';
	}
	document.getElementById('print_page_id').value=val;
}


function pagePrint(){
	var id=document.getElementById('print_page_id').value;
	var page_name='';
	var url = 'print.php?p_id='+id;
	if(window.location.href.indexOf('common_pages.php') != -1){
		page_name='common_pages.php';
	}else if(window.location.href.indexOf('common_education.php') != -1){
		page_name='common_education.php';
	}else if(window.location.href.indexOf('location.php') != -1){
		page_name='location.php';
		url='print_location.php';
	}else if(window.location.href.indexOf('common_news.php') != -1){
		page_name='print_news.php';
		url=page_name+'?id='+id;
	}
	openWindow(url,650,500,'yes');
}