// JavaScript Document
var xmlHttp
var state="no";
function checks(str)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 }
	var url="check.php"
	url=url+"?mobile="+str
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 	
	 				
					state="no";
					if(xmlHttp.responseText==1) {
					alert('The mobile number you have entered is already registered');
				    state="yes";	
					return false;
					}
					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 toggle_visibility(id) {
        var e = document.getElementById(id);
        if(e.style.display == 'none')
        e.style.display = 'inline';
        else
        e.style.display = 'none';
}

function validateForm(theForm)
{
 	var login = document.getElementById('login');
	var email = document.getElementById('email');
	var password = document.getElementById('password');
	var phone=document.getElementById('phone');
	var client=document.getElementById('client');
	var address=document.getElementById('address');
	var logo=document.getElementById('logo');
	
	// Check each input in the order that it appears in the form!
	if(isAlphabet(login, "Please enter only letters for login")){
		if(emailValidator(email, "Please enter a valid email address")){
			if(isAlphanumeric(password, "Please enter the password")){
				if(isNumeric(phone, "Please enter a valid phone number")){
					if(isAlphabet(client, "Please enter only letters for Client Company")){
						if(isAlphanumeric(address, "Numbers and Letters Only for Address")){
							if(isNumeric(logo, "Please enter the Logo")){
								return true;
							}
						}
					}
				}
			}
		}
	}
		
	return false;
	
	
}

function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return true;
	}
	return false;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

  
 function emailValidator(elem, helperMsg){
	
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		
		return false;
	}
}

function validated(obj)
{
	
	err="";
	var name = obj.name.value;
	var sname = obj.surname.value;
	var email = obj.email.value;
	var mobile=obj.mobile.value;
	if(name=='' || name=='Name..')
	err=err+" ----First Name\n"
	if(sname=='' || sname=='Surame..')
	err=err+" ----Surname\n"
	if(email=='' || email=='Email Address..')
	err=err+" ----Email\n"
	if(mobile=='' || mobile=='Mobile Phone Number..')
	err=err+" ----Mobile Number\n"
	
	if(email!="" && !emailValidator(obj.email, "Please enter a valid email address") && email!='Email Address..')
	err=err+" ----Valid Email\n"
	
	
	if(err!=''){
	alert("Please enter the following details:\n"+err);
	return false;
	}
	
	checks(mobile);
	if(state=="yes")
	return false;
	else
	return true;
	
	

		
	
	
}
	
function validate(obj)
{
	err=""
	if(obj) 	d = obj.getElementsByTagName('input');
	else		d = document.getElementsByTagName('input');
	j=0;
	index='';
	var cl = new Array()
	for(i=0;i<d.length;i++)
	{	val=d[i].name
		valw=d[i].id

		if(valw=="")
		continue;

	if(val!="submit" && val!='thumpimg' && val!='address1' && val!='fax' && val!='folderID' && val!='fcontact' && val!='faddress' && val != "coordinatex" && val != "coordinatey"){
		if(d[i].value == '' || d[i].value == 'Name..' || d[i].value == 'Email Address..' || d[i].value == 'Mobile Phone Number..')
		{	if(j==0){
			index=i
			}
			
			err=err+" ----"+valw+"\n"
			j++
		}
		if((d[i].value!= '' ) && (d[i].name =='email'))
		{
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w{2,25})*(\.\w{2,3})+$/.test(d[i].value))
			{
				
			}
			else
			{
				if(j==0){
				index=i
				}
				err=err+"-----Valid "+valw+"\n"
			}
		}
		if((d[i].value!= '') && (d[i].name =='web'))
		{
				var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
				if(RegExp.test(d[i].value)){
					
				}else{
						if(j==0){
						index=i
						}
					err=err+"-----Valid "+valw+"\n"
				} 
		}
		if((d[i].value!="") && (d[i].name=='ran' || d[i].name=='hr' ||  d[i].name=='min' || d[i].name=='mobile'))
		{
			if(d[i].name=='mobile' && (d[i].value.length<11 || isNaN(d[i].value) )){
			err=err+"-----Valid "+valw+"\n"
		   }
			else
			{
				if (!isNaN(d[i].value))
				{
				}
				else
				{
					if(j==0){
						index=i
		    		}
					err=err+"-----Valid "+valw+"\n"
				}	
			}
		}}
		if((d[i].value!="") && (d[i].name=='hr' || d[i].name=='min'))
		{
			
			if(d[i].name=='hr' && d[i].value>23)
			err=err+"-----Valid "+d[i].id+"\n"
			
			if(d[i].name=='minute' && d[i].value>60)
			err=err+"-----Valid "+d[i].id+"\n"
			
		}
	}
	//
	if(obj) 	d = obj.getElementsByTagName('select');
	else		d = document.getElementsByTagName('select');
	j=0;
	index='';
	var cl = new Array()
	for(i=0;i<d.length;i++)
	{	val=d[i].name
		valw=d[i].title

		if(valw=="")
		continue;
		
		if(d[i].value == '' || d[i].value == 'choose' || d[i].value == 'Choose' || d[i].value == 'Select')
		{	if(j==0){
			index=i
			}
			
			err=err+" ----"+valw+"\n"
			j++
		}
	}
	
	if(obj) 	d = obj.getElementsByTagName('textarea');
	else		d = document.getElementsByTagName('textarea');
	j=0;
	index='';
	var cl = new Array()
	for(i=0;i<d.length;i++)
	{	val=d[i].name
		valw=d[i].title

		if(valw==""){
		continue;
		}
		
		if(d[i].value == '')
		{	if(j==0){
			index=i
			}
			
			err=err+" ----"+valw+"\n"
			j++
		}
	}
	//
	if(document.area){
	if(document.area.altemail && document.area.altemail.value!="")	
	{
			str=document.area.altemail.value;
			if(str.search(/,/i)==-1)
			{
				if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w{2,25})*(\.\w{2,3})+$/.test(str)))
				{
					err=err+"-----Valid alternate emails\n"
				}
			}
			else
			{
				var er=0;
				subst=str.split(',');
				for(i=0;i<subst.length;i++)
				{
					if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w{2,25})*(\.\w{2,3})+$/.test(subst[i])))
					{
						er=1;
					}
				}
				if(er!=0)
				{
					err=err+"-----Valid alternate emails\n"
				}
				
			}
			
	}
	}	
	
	if(err!="")
	{
		alert("Please enter the following details:\n"+err);
		if(index!=''){		d[index].focus(); }
		return false;
	}
	
		
		
}

function showme(str)
{
	
	for(i=1;i<=2;i++)
	{
		if(i==str)	{
		st="document.getElementById('mail_set"+i+"').style.display='block'";	
		eval(st);
		}
		else {
		st="document.getElementById('mail_set"+i+"').style.display='none'";	
		eval(st); 
		}
	}
	
	
}

function validate_profile()
{
	err=""
	d = document.getElementsByTagName('input');
	j=0;
	index='';
	var cl = new Array()
	for(i=0;i<d.length;i++)
	{	val=d[i].name
		valw=d[i].id

		if(valw=="")
		continue;

	if(val!="submit" && val!='thumpimg' && val!='address1' && val!='fax' && val!='folderID' && val!='fcontact' && val!='address'&& val!='remark'){
		if(d[i].value == '' || d[i].value == 'Name..' || d[i].value == 'Email Address..' || d[i].value == 'Mobile Phone Number..')
		{	if(j==0){
			index=i
			}
			if((d[i].name != 'password')&& (d[i].name != 'cpassword')){
				err=err+" ----"+valw+"\n"
				j++
			}
		}
		if((d[i].value!= '' ) && (d[i].name =='email'))
		{
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w{2,25})*(\.\w{2,3})+$/.test(d[i].value))
			{
				
			}
			else
			{
				if(j==0){
				index=i
				}
				err=err+"-----Valid "+valw+"\n"
			}
		}
		if((d[i].value!= '') && (d[i].name =='web'))
		{
				var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
				if(RegExp.test(d[i].value)){
					
				}else{
						if(j==0){
						index=i
						}
					err=err+"-----Valid "+valw+"\n"
				} 
		}
		if((d[i].value!="") && (d[i].name=='ran' || d[i].name=='hr' ||  d[i].name=='min' || d[i].name=='mobile'))
		{
			if(d[i].name=='mobile' && (d[i].value.length<11 || isNaN(d[i].value) )){
			err=err+"-----Valid "+valw+"\n"
		   }
			else
			{
				if (!isNaN(d[i].value))
				{
				}
				else
				{
					if(j==0){
						index=i
		    		}
					err=err+"-----Valid "+valw+"\n"
				}	
			}
		}}
		if((d[i].value!="") && (d[i].name=='hr' || d[i].name=='min'))
		{
			
			if(d[i].name=='hr' && d[i].value>23)
			err=err+"-----Valid "+d[i].id+"\n"
			
			if(d[i].name=='minute' && d[i].value>60)
			err=err+"-----Valid "+d[i].id+"\n"
			
		}
	}
	if(document.area){
		if(document.area.altemail && document.area.altemail.value!="")	
		{
				str=document.area.altemail.value;
				if(str.search(/,/i)==-1)
				{
					if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w{2,25})*(\.\w{2,3})+$/.test(str)))
					{
						err=err+"-----Valid alternate emails\n"
					}
				}
				else
				{
					var er=0;
					subst=str.split(',');
					for(i=0;i<subst.length;i++)
					{
						if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w{2,25})*(\.\w{2,3})+$/.test(subst[i])))
						{
							er=1;
						}
					}
					if(er!=0)
					{
						err=err+"-----Valid alternate emails\n"
					}
					
				}
				
		}
		}	
	
	if((document.form1.password.value=='') && (document.form1.cpassword.value==""))	
	{
	}else{
		
		if(document.form1.password.value==''){
				err=err+" ----"+document.form1.password.id+"\n";
		}
		if(document.form1.cpassword.value==''){
				err=err+" ----"+document.form1.cpassword.id+"\n";
		}
		if((document.form1.password.value!='') && (document.form1.cpassword.value!="") && (document.form1.password.value!=document.form1.cpassword.value))	
		{
			err=err+" ----"+'Password Not Matched'+"\n";
		}
	}
	if(err!="")
	{
		alert("Please enter the following details:\n"+err);
		if(index!=''){		d[index].focus(); }
		return false;
	}
	
		
		
}


function delete_confirmation(obj,txt,title){
	conftxt = 'Would you like to Delete this '+txt;
	if(title)
		conftxt = conftxt+' named '+title;
	conftxt = conftxt+'?';
	if(confirm(conftxt)){
		document.location.href=obj.href;
	}else{
		return false;
	}
}

function delete_confirmationUrl(url,txt,title){
	conftxt = 'Would you like to Delete this '+txt;
	if(title)
		conftxt = conftxt+' named '+title;
	conftxt = conftxt+'?';
	if(confirm(conftxt)){
		document.location.href=url;
	}else{
		return false;
	}
}



function validate_mail(obj)
{
	err=""
	if(obj) 	d = obj.getElementsByTagName('input');
	else		d = document.getElementsByTagName('input');
	j=0;
	index='';
	var cl = new Array()
	for(i=0;i<d.length;i++)
	{	val=d[i].name
		valw=d[i].id

		if(valw=="")
		continue;
		
		if(d[i].type == 'hidden' || d[i].type == 'radio' || d[i].type == 'checkbox')
		continue;

	if(val!="submit" && val!='thumpimg' && val!='address1' && val!='fax' && val!='folderID' && val!='fcontact' && val!='faddress' && val != "coordinatex" && val != "coordinatey"){
		if(d[i].value == '' || d[i].value == 'Name..' || d[i].value == 'Email Address..' || d[i].value == 'Mobile Phone Number..')
		{	if(j==0){
			index=i
			}
			
			err=err+" ----"+valw+"\n"
			j++
		}
		if((d[i].value!= '' ) && (d[i].name =='email'))
		{
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w{2,25})*(\.\w{2,3})+$/.test(d[i].value))
			{
				
			}
			else
			{
				if(j==0){
				index=i
				}
				err=err+"-----Valid "+valw+"\n"
			}
		}
	}	
	}
	if(document.formmail){
	if(document.formmail.message && document.formmail.message.value!="")	
	{
			
			
	}else{
		err=err+"-----Mail Content\n"
	}
	}
	var user_count = document.getElementById('usr_count').value;
	var user_checked = false;
	for(var uc = 1; uc<=user_count; uc++){
		id = 'usr_'+uc;
		if(document.getElementById(id).checked){
			user_checked = true;
			break;
		}
	}
	if(!user_checked){
		err=err+"-----Select User\n"
	}
	

	if(err!="")
	{
		alert("Please enter the following details:\n"+err);
		if(index!=''){		d[index].focus(); }
		return false;
	}
	
		
		
}




var x_offset_tooltip = 5;
var y_offset_tooltip = 0;
/* Don't change anything below here */

var popup_Obj = false;
var popup_iframe = false;


var ajax_tooltip_MSIE = false;
var last_object;
if(navigator.userAgent.indexOf('MSIE')>=0)ajax_tooltip_MSIE=true;


function ajax_showPopup(msg,iconclass)
{
	if(!popup_Obj)	/* Tooltip div not created yet ? */
	{
		popup_Obj = document.createElement('DIV');
		popup_Obj.className = 'popup';
		popup_Obj.id = 'popup';		
		document.body.appendChild(popup_Obj);

		
		var popup_head = document.createElement('DIV');	/* Create navigation panel div */
		popup_head.className='popup_head';
		popup_Obj.appendChild(popup_head);
		
		//pop up header
		
				
		//pop up header finish

		var contentiDiv = document.createElement('DIV'); /* Create tooltip content div */
		contentiDiv.id = 'popup_icon';
		//contentDiv.style.backgroundColor = '#d9eefd';
		popup_Obj.appendChild(contentiDiv);

		if(!iconclass) iconclass = 'success';
		iconclass = iconclass+'_icon';
		contentiDiv.className = iconclass;
		
		var contentDiv = document.createElement('DIV'); /* Create tooltip content div */
		contentDiv.id = 'popup_body';
		contentDiv.innerHTML = msg;
		//contentDiv.style.backgroundColor = '#d9eefd';
		popup_Obj.appendChild(contentDiv);


		var closeDiv = document.createElement('DIV'); /* Create tooltip content div */
		closeDiv.id = 'closebtn';
		popup_Obj.appendChild(closeDiv);

		var closebtn = document.createElement('Input');
		closebtn.type = 'button';
		closebtn.value = 'Close';
		closebtn.onclick = ajax_hidepopup;
		closeDiv.appendChild(closebtn);
		
		
		if(ajax_tooltip_MSIE){	/* Create iframe object for MSIE in order to make the tooltip cover select boxes */
			popup_iframe = document.createElement('IFRAME');
			popup_iframe.style.position = 'absolute';
			popup_iframe.border='0';
			popup_iframe.id='popup_iframe';
			popup_iframe.frameborder=0;
			popup_iframe.style.backgroundColor='#FFF';
			popup_iframe.src = 'about:blank';
			popup_iframe.style.zIndex = 90;
		}

		popupc_Obj = document.createElement('DIV');
		popupc_Obj.id = 'popup_cover';		
		document.body.appendChild(popupc_Obj);
	}
	popup_Obj.style.display='block';
	ajax_positionpopup_center();
}


function ajax_hidepopup()
{
	popup_Obj = document.getElementById('popup');	
	//popup_Obj.style.display='none';
	document.body.removeChild(popup_Obj);
	popupc_Obj = document.getElementById('popup_cover');
	document.body.removeChild(popupc_Obj);
	popup_Obj = false;
	if(ajax_tooltip_MSIE)
	{
		//popup_iframe.style.display='none';
		document.body.removeChild(document.getElementById('popup_iframe'));
		popup_iframe = false;
	}
}

function ajax_positionpopup_center()
{	
	var tooltipWidth = document.getElementById('popup').offsetWidth;
	var doc_width = document.body.scrollWidth;
	var left_pos = parseInt(parseInt(doc_width - body_width) / 2)+ parseInt((body_width - tooltipWidth)/2); 
	document.getElementById('popup').style.left = left_pos + 'px';
}