var j = jQuery.noConflict();
var xmlHttp

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 checkAvailable()
{
	var Name = document.contactUsForm.username.value;
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="http://dentalpartners.com.au/media/server-scripts/checkavail.php";
	url=url+"?Name="+Name;
	alert(url);
	//document.getElementById("image").style.display='block';
	xmlHttp.onreadystatechange=stateChangedavail;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function stateChangedavail() 
{
	//alert(xmlHttp.readyState);
	if(xmlHttp.readyState==4)
	{ 
	alert(xmlHttp.responseText);
	if(xmlHttp.responseText==1)
	{
	//return false;	
	}
	else
	{
	//return false;	
	}
	//return false;
	}
//return false;	
}

function forgotpass()
{ 
var Name = document.forgotform.contact_name.value;
var Phone = document.forgotform.phone.value;
var Email = document.forgotform.email.value;
var time = document.forgotform.practice_name.value;

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/media/server-scripts/forgot.php";
url=url+"?Name="+encodeURIComponent(Name)+"&Phone="+encodeURIComponent(Phone)+"&Email="+encodeURIComponent(Email)+"&time="+encodeURIComponent(time);
	if(document.getElementById("success"))
		document.getElementById("success").style.display='none';
	if(document.getElementById("fail"))
		document.getElementById("fail").style.display='none';
xmlHttp.onreadystatechange=stateChangedforgot;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChangedforgot() 
{ 
	if (xmlHttp.readyState==4)
	{
		document.getElementById("success").style.display='block';
		document.forgotform.reset();		
	}
}


function joindental()
{ 
var iam = document.contactUsForm.iam.value;
var iaminterested = document.contactUsForm.iaminterested.value;
var Name = document.contactUsForm.Name.value;
var Phone = document.contactUsForm.Phone.value;
var Email = document.contactUsForm.Email.value;
var time = document.contactUsForm.time.value;
var practicename = document.contactUsForm.practicename.value;
var address= document.contactUsForm.address.value;
var website = document.contactUsForm.website.value;

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/media//server-scripts/join-dental-partners.php";
url=url+"?iam="+encodeURIComponent(iam)+"&iaminterested="+encodeURIComponent(iaminterested)+"&Name="+encodeURIComponent(Name)+"&Phone="+encodeURIComponent(Phone)+"&Email="+encodeURIComponent(Email)+"&time="+encodeURIComponent(time)+"&practicename="+encodeURIComponent(practicename)+"&address="+encodeURIComponent(address)+"&website="+encodeURIComponent(website);
	if(document.getElementById("success"))
		document.getElementById("success").style.display='none';
	if(document.getElementById("fail"))
		document.getElementById("fail").style.display='none';

document.getElementById("image").style.display='block';
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	if(xmlHttp.responseText==1)
	{
		pageTracker._trackPageview("/JoinDentalPartnersSuccess");		
		document.getElementById("success").style.display='block';
		document.getElementById("image").style.display='none';
		document.contactUsForm.reset();		
	}
	else
	{
		document.getElementById("fail").style.display='block';
		document.getElementById("image").style.display='none';		
	}
	}
}

function sendcontact()
{ 
var Name = document.ContactUsNew.Name.value;
var Phone = document.ContactUsNew.Phone.value;
var Email = document.ContactUsNew.Email.value;
var time = document.ContactUsNew.time.value;
var commentbox = document.ContactUsNew.commentbox.value;

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/media//server-scripts/inquiry.php";
url=url+"?Name="+encodeURIComponent(Name)+"&Phone="+encodeURIComponent(Phone)+"&Email="+encodeURIComponent(Email)+"&time="+encodeURIComponent(time)+"&commentbox="+encodeURIComponent(commentbox);
	if(document.getElementById("success"))
		document.getElementById("success").style.display='none';
	if(document.getElementById("fail"))
		document.getElementById("fail").style.display='none';
document.getElementById("image").style.display='block';
xmlHttp.onreadystatechange=stateChanged1;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged1() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	if(xmlHttp.responseText==1)
	{
		pageTracker._trackPageview("/ContactSuccess");
		document.getElementById("success").style.display='block';
		document.getElementById("image").style.display='none';
		document.ContactUsNew.reset();		
	}
	else
	{
		document.getElementById("fail").style.display='block';
		document.getElementById("image").style.display='none';		
	}
	}
}


function validateformNewwwww(){
var why = "";
var show = false;
var feildfocus = false;
boxone=false; boxtwo=false;  boxthree=false; boxfive = false;
if(document.ContactUsNew.Name.value == ""){
 why+="Please enter your name<br />";
 show = true;
 boxone=true;
}



if(document.ContactUsNew.contactme[1].checked == false){
	if(document.ContactUsNew.Email.value =='')
	{
	 why+="Please Enter Email id<br />";
	 show = true;
	 boxfive=true;
	}
}



if(document.ContactUsNew.contactme[0].checked == true)
{
	if(document.ContactUsNew.Phone.value.length<1 || (CheckPhoneNumber(document.ContactUsNew.Phone.value)==false)){
	 why+="Please enter a valid phone number<br />";
	 show = true;
	 boxfour=true;
	}

}

if(document.ContactUsNew.contactme[1].checked == true)
{
	if(isEmail(document.ContactUsNew.Email.value)==false){
	 why+="Please enter a valid email address <br />";
	 show = true;
	 boxtwo=true;
	}

}
 if(show){
   alert(why);
  if(boxone)
  document.ContactUsNew.Name.focus();
  if(document.ContactUsNew.contactme[0].checked == true)
  document.ContactUsNew.Phone.focus();  
  if(document.ContactUsNew.contactme[1].checked == true)
  document.ContactUsNew.Email.focus();    
  return false;
 }
 sendcontact();
 return false;
}



function forgotpasssvalid(){
var why = "";
var show = false;
var feildfocus = false;
boxone=false; boxtwo=false;  boxthree=false; boxfive = false;
if(document.forgotform.practice_name.value == ""){
 why+="Please enter practice name\n";
 show = true;
 boxone=true;
}

if(document.forgotform.contact_name.value == ""){
 why+="Please enter contact name\n";
 show = true;
 boxtwo=true;
}
if(isEmail(document.forgotform.email.value)==false){
 why+="Please enter email\n";
 show = true;
 boxthree=true;
}

if(document.forgotform.phone.value.length<1 || (CheckPhoneNumber(document.forgotform.phone.value)==false)){
why+="Please enter phone number\n";
 show = true;
 boxfive=true;
}

 if(show){
   alert(why);
  if(boxfive)
  document.forgotform.phone.focus();   
  if(boxthree)
  document.forgotform.email.focus();
  if(boxtwo)
  document.forgotform.contact_name.focus();  
  if(boxone)
  document.forgotform.practice_name.focus();
  return false;
 }
else
 {
 forgotpass();
 }
 return false;
}





function validateformmmmmmm(){
var why = "";
var show = false;
var feildfocus = false;
boxone=false; boxtwo=false;  boxthree=false; boxfive = false;
if(document.contactUsForm.Name.value == ""){
 why+="Please enter your name<br />";
 show = true;
 boxone=true;
}



if(document.contactUsForm.contactme[0].checked == false && document.contactUsForm.contactme[1].checked == false){
 why+="Please Select either phone or email<br />";
 show = true;
 boxfive=true;
}



if(document.contactUsForm.contactme[0].checked == true)
{
	if(document.contactUsForm.Phone.value.length<1 || (CheckPhoneNumber(document.contactUsForm.Phone.value)==false)){
	 why+="Please enter a valid phone number<br />";
	 show = true;
	 boxfour=true;
	}

}

if(document.contactUsForm.contactme[1].checked == true)
{
	if(isEmail(document.contactUsForm.Email.value)==false){
	 why+="Please enter a valid email address <br />";
	 show = true;
	 boxtwo=true;
	}

}
 if(show){
   alert(why);
  if(boxone)
  document.contactUsForm.Name.focus();
  if(document.contactUsForm.contactme[0].checked == true)
  document.contactUsForm.Phone.focus();  
  if(document.contactUsForm.contactme[1].checked == true)
  document.contactUsForm.Email.focus();    
  return false;
 }
joindental();
return false;
}

function loginSubmit(){
var why = "";
//var show = false;
//var feildfocus = false; 
//boxone=false; boxtwo=false;  boxthree=false; boxfive = false;


if(document.loginform.username.value == ""){
 why+="Please enter username<br />";
 //show = true;
 //boxone=true;
}

if(document.loginform.password.value == ""){
 why+="Please enter Password<br />";
 //show = true;
 //boxtwo=true;
}

 if(why!="")
	{
	showDialogone('Login to Partner Community',why,'warning');
	return false;
	   
	}
	else
	{
	CheckLogin();
	}
return false;
	
}

function changePasswordfrm(){
var why = "";
//var show = false;
//var feildfocus = false; 
//boxone=false; boxtwo=false;  boxthree=false; boxfive = false;


if(document.changepassword.password.value == ""){
 why+="Please enter password<br />";
 //show = true;
 //boxone=true;
}

 if(why!="")
	{
	showDialog('Change Password',why,'warning');
	return false;
	   
	}
	else
	{
	changePassword();
	}
return false;
	
}

function NetloginSubmit(){
var why = "";
//var show = false;
//var feildfocus = false; 
//boxone=false; boxtwo=false;  boxthree=false; boxfive = false;


if(document.netLogin.email.value == ""){
 why+="Please enter username<br />";
 //show = true;
 //boxone=true;
}

if(document.netLogin.password.value == ""){
 why+="Please enter Password<br />";
 //show = true;
 //boxtwo=true;
}

 if(why!="")
	{
	showDialogone('Login to NetSuite',why,'warning');
	return false;
	   
	}
	else
	{
	return true;
	}
return false;
	
}

function anothergotofocus()
	{
		
		
		    if(document.loginform.username.value=="")	
		    document.loginform.username.focus();
			else if(document.loginform.password.value=="")
			 document.loginform.password.focus();
			 
	}
 
 
 











function loginSubmit1(){
var why = "";
var show = false;
var feildfocus = false;
boxone=false; boxtwo=false;  boxthree=false; boxfive = false;
if(document.loginform1.username.value == ""){
 why+="Please enter username<br />";
 show = true;
 boxone=true;
}

if(document.loginform1.password.value == ""){
 why+="Please enter Password<br />";
 show = true;
 boxtwo=true;
}

 if(show){
   alert(why);
  if(boxtwo)
  document.loginform1.password.focus();
  if(boxone)
  document.loginform1.username.focus();  
  
  return false;
 }
}

function isEmail( strValue) {
 var objRegExp = /^[a-z]\w*([.\-]\w+)*@[a-z]\w*([.\-]\w+)*\.[a-z]{2,3}$/i;
 return objRegExp.test(strValue);
}
function CheckPhoneNumber(TheNumber) {
 var valid = 1
 var GoodChars = "0123456789()-+.$ "
 var i = 0
 if (TheNumber=="") {
 // Return false if number is empty
 valid = 0
 }
 for (i =0; i <= TheNumber.length -1; i++) {
 if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
// Note: Remove the comments from the following line to see this
// for loop in action.
// alert(TheNumber.charAt(i) + " is no good.")
 valid = 0
 } // End if statement
 } // End for loop
 return valid
}



// Member Login Add Jquery Start

function addMemberfrm(update,jobid){
		var why = '';
		var frmadd = document.addMemberForm;
		var title = document.addMemberForm.title.value;
		var state = document.addMemberForm.state.value;
		var location = document.addMemberForm.location.value;
		var submissiondate = document.addMemberForm.submissiondate.value;
		var submissionmonth = document.addMemberForm.submissionmonth.value;
		var submissionyear = document.addMemberForm.submissionyear.value;
		var salary_range = document.addMemberForm.salary_range.value;
		var contact = document.addMemberForm.contact.value;
		var emp_type = document.addMemberForm.emp_type.value;
		var Contact_Number = document.addMemberForm.Contact_Number.value;
		var Contact_Email = document.addMemberForm.Contact_Email.value;		
		var position_desc = document.addMemberForm.position_desc.value;
		var essen_creteria = document.addMemberForm.essen_creteria.value;
		var desire_creteria = document.addMemberForm.desire_creteria.value;
		var partner_id = document.addMemberForm.partner_id.value;
		var update = update;
		var jobid = jobid;
		var todaysdate = new Date();
		var submitclose = submissionyear+'-'+submissionmonth+'-'+submissiondate;
		var submitclose1 = submissiondate+'/'+submissionmonth+'/'+submissionyear;
		
		var endDate = new Date(submitclose1);
		if(title == ""){
			 why+="Please enter position title<br />";
		}
		if(state=='')
		{
			why+="Please select state<br />";
		}
		
		if(location=='')
		{
			why+="Please enter location<br />";
		}
		
/*		if(submitclose=='')
		{
			alert("Please choose submissions close date");
			return false;
		}
*/
		if(submissiondate=='')
		{
			why+="Please select date<br />";
		}
		if(submissionmonth=='')
		{
			why+="Please select month<br />";
		}
		if(submissionyear=='')
		{
			why+="Please select year<br />";
		}
		if(!update)
		{
			if(endDate < todaysdate)
			{
				why+="Submissions close date should not be less than the current date<br />";
			}		
		}
		/*if(salary_range=='')
		{
			why+="Please enter salary range<br />";
			var salary_ran = 'checkvalid';
		}
		if(salary_ran != 'checkvalid')
		{
			if(CheckPhoneNumber(document.addMemberForm.salary_range.value)==false)
			{
				why+="Please enter valid salary range<br />";
			}		
		}*/
		if(contact=='')
		{
			why+="Please enter contact<br />";
		}

		if(emp_type=='')
		{
			why+="Please select employment type<br />";
		}
		
		if(Contact_Number=='')
		{
			why+="Please enter contact number<br />";
		}

		if(Contact_Email=='')
		{
			why+="Please enter contact email<br />";
		}
		
		
/*		if(position_desc=='')
		{
			alert("Please enter position description");
			return false;
		}
		
		if(essen_creteria=='')
		{
			alert("Please enter essential criteria");
			return false;
		}


		if(desire_creteria=='')
		{
			alert("Please enter desirable criteria");
			return false;
		}*/

	if(document.getElementById("success"))
		document.getElementById("success").style.display='none';
	if(document.getElementById("fail"))
		document.getElementById("fail").style.display='none';
	//document.getElementById("image").style.display='block';		
 if(why!="")
 {
	showDialog('Member Job Listing - Add',why,'warning');
	return false;	 
 }
else
{
	if(update)
	{
		
				var html= j.ajax({
					 type: "POST",
					url: '/media/server-scripts/member-edit.php?',
					 async: false,
		
					data: "jobid="+jobid+"&partner_id="+partner_id+"&title="+title+"&state="+state+"&location="+location+"&submission="+submitclose+"&salary_range="+salary_range+"&contact="+contact+"&emp_type="+emp_type+"&Contact_Number="+Contact_Number+"&Contact_Email="+Contact_Email+"&position_desc="+position_desc+"&essen_creteria="+essen_creteria+"&desire_creteria="+desire_creteria
		 }).responseText;
		
				if(html==1)
				{
				document.getElementById("success2").style.display='none';
				//document.getElementById("image").style.display='none';
				//document.addMemberForm.reset();
				//setTimeout("document.getElementById('success').style.display='none'",6000);
				document.getElementById("success1").style.display='block';
				//setTimeout("window.location.href='/member-edit';",3000);				
				return false;		
				}
				
				if(html==2)
				{
					alert("Not updated Successfully")
				}
							
		
	}
	else
	{
				var html= j.ajax({
					 type: "POST",
					url: '/media/server-scripts/member.php?',
					 async: false,
		
					data: "partner_id="+partner_id+"&title="+title+"&state="+state+"&location="+location+"&submission="+submitclose+"&salary_range="+salary_range+"&contact="+contact+"&emp_type="+emp_type+"&Contact_Number="+Contact_Number+"&Contact_Email="+Contact_Email+"&position_desc="+position_desc+"&essen_creteria="+essen_creteria+"&desire_creteria="+desire_creteria
		 }).responseText;
		
				if(html==1)
				{
				document.getElementById("success2").style.display='none';
				//document.getElementById("success3").style.display='none';				
				//document.getElementById("image").style.display='none';
				//document.addMemberForm.reset();
				//setTimeout("document.getElementById('success').style.display='none'",6000);
				document.getElementById("success1").style.display='block';				
				setTimeout("window.location.href='/memberinadd';",5000);
				return false;		
				}
				
				if(html==2)
				{
					alert("Not Added Successfully")
				}
					
	}
		
}
	return false;	
	}


// Member Login Add Jquery End

//Member Login Delete Listings Start

function deleteItem(jobid){
	var r=confirm("Are you sure want to delete");

		if(r==true)
		{
				var html= j.ajax({
					 type: "POST",
					url: '/media/server-scripts/member-delete.php?',
					 async: false,
		
					data: "jobid="+jobid
		 }).responseText;
		
				if(html==1)
				{
				alert("Deleted Successfully")
				window.location.href = '/member-edit';
				return false;		
				}
				
				if(html==2)
				{
					alert("Not Deleted Successfully")
				}
		}
		else
		return false;
	
		
	}		
	
function CheckLogin(){
	var username = document.loginform.username.value;
	var password = document.loginform.password.value;
	
		var html= j.ajax({
			 type: "POST",
			url: '/media/server-scripts/Checklogin.php?',
			 async: false,		
			data: "username="+username+"&password="+password
		 }).responseText;
				if(html==1)
				{
				document.loginform.submit();
				}
				if(html==0)
				{
				showDialogone('Partner Login','Login Authentication Failed. <br>Please enter valid Username and Password.','warning');
				document.loginform.reset();
				return false;
				}	
	
		
	}			

function changePassword(){
	var password = document.changepassword.password.value;
	var partner_id = document.changepassword.partner_id.value;
		var html= j.ajax({
			 type: "POST",
			url: '/media/server-scripts/changePassword.php?',
			 async: false,		
			data: "password="+password+"&partner_id="+partner_id
		 }).responseText;
				if(html==1)
				{
					showDialog('Change Password','Password Changed Successfully','warning');
					//return false;					
					window.location.href = '/member';						
				}
				if(html==0)
				{
					showDialog('Change Password','Error - While Changing Password','warning');				
				return false;
				}	
	
		
	}
function SwitchState(){
	var state = document.getElementById("state").value;
	document.location.href = '/member-view/state/'+state;
}

function changeForm(){
	//document.getElementById("partner-login").style.display = 'none';
	//document.getElementById("netsuite-login").style.display = 'block';
	document.totalForm.netSuite.checked = true;
	document.totalForm.partner.checked = false;
window.open("https://system.netsuite.com/pages/customerlogin.jsp?country=AU", "mywindow","location=1,status=1,scrollbars=1,resizable=1");
	
}
function changeForm1(){
	document.getElementById("partner-login").style.display = 'block';
	document.getElementById("netsuite-login").style.display = 'none';	
	document.totalForm.netSuite.checked = false;
	document.totalForm.partner.checked = true;
}

//Member Login Delete Listings End
