/*
//////////////////////////////////////////////////////////////////////////////////////////////////////
//	File				: functions.js
##
##	Created By			: Mathlesh Kumar
##
##	Created On			: Novermber 07th, 2005
##
##	Purpose				: This file contains javascript functions which will be used all over the site
/////////////////////////////////////////////////////////////////////////////////////////////////////
*/
function checkPasswords()
{
		var obj=document.change_password
		
				if(obj.new_password.value=="")
		{
			alert("Please enter the password")
			obj.new_password.focus();
			return false;
		}
		if(obj.new_password.value!=obj.repeat_password.value)
		{
			alert("Password and confirm password fields doesn't match")
			obj.repeat_password.focus();
			return false;
		}
	return true;
}
//ajax function to start grabbing some resources
function getSearch(str)
{
hideLayer('search_frame');

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)  {  alert ("Your browser does not support AJAX!");  return;  } 

str = replaceChars(str);
var url="^p_main''.php";
url=url+"?kwd="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

showLayer('search_frame');

} 


// ajax function used to display results after getting data
function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{

var g_rank = xmlHttp.responseText
document.getElementById("result_table").innerHTML= g_rank;

}

}



//ajax function to start grabbing some resources
function checkUsername(email)
{

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)  {  alert ("Your browser does not support AJAX!");  return;  } 

var url="^p_registration''.php";
url=url+"?username="+email;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=usernameResults;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);


} 


// ajax function used to display results after getting data
function usernameResults() 
{ 
if (xmlHttp.readyState==4)
	{ 
		var results = xmlHttp.responseText;
		document.getElementById("frmButton").disabled = "yes";
		if (results == "\nno")
		{document.getElementById("result_table").innerHTML= '<img src="images/icons/delete.gif">';  }
		if (results == "\nexists") { document.getElementById("result_table").innerHTML= '<img src="images/icons/delete.gif">'; alert("This email address is allready registered with Favoritzy.");} 
		if (results == "\nyes") { document.getElementById("result_table").innerHTML= '<img src="images/icons/ico_done16.gif">'; document.getElementById("frmButton").disabled = false;}
		
	}
}
// internal AJAX function
function GetXmlHttpObject()
{
var xmlHttp=null;
try { xmlHttp=new XMLHttpRequest(); } // Firefox, Opera 8.0+, Safari
catch (e)  {  // Internet Explorer
try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } }
return xmlHttp;
}


function replaceChars(entry) {
out = " "; // replace this
add = "+"; // with this
temp = "" + entry;

while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add + 
temp.substring((pos + out.length), temp.length));
}
return(temp);
}



/* writes some text into document on certain droplist change */
function checkDroplist()
{	
	if (document.bid.type.value != "Permanent Link")
	{
		document.bid.pay_type.value = "per month";
	}
	else document.bid.pay_type.value = "";
}


function hideLayer(id)
{ document.getElementById(id).style.display = ""; }

function showLayer(id)
{ document.getElementById(id).style.display = "block"; }

/* toggle layers for hiding and unhiding */
function toggleLayer(whichLayer)
{
if (document.getElementById)
{
// this is the way the standards work
var style2 = document.getElementById(whichLayer).style;
}
else if (document.all)
{
// this is the way old msie versions work
var style2 = document.all[whichLayer].style;
}
else if (document.layers)
{
// this is the way nn4 works
var style2 = document.layers[whichLayer].style;
}
	style2.display = style2.display? "":"block";

}

function NewWin(id,x,y) {
	if((x*1 == NaN) || (x == ""))x = 800;
	if((y*1 == NaN) || (y == ""))y = 400;
	window.open("_popup.php?id="+id, "Langas", "resizable=yes,scrollbars=yes,status=no,menubar=yes,titlebar,height="+y+",width="+x+"");
}

function inputDomainFocus (target) { if (target.value == 'your-domain.com') target.value = ''; }
function inputDomainBlur (target) {	if (target.value == '') target.value = 'your-domain.com';	}

function go(loc) { window.location.href = loc; }


function taskConfirmation(thisform)
{
	with (thisform)
{
	conf = confirm("Are you sure you want to save this task with following parameters? Order Name: "+project_name.value+", Assigned To: "+assigned_to.value+", Pay Type: "+pay_type.value+", Price: $"+price.value+", Alert Asignee: "+alert_user.checked+", Alert Client: "+alert_client.checked);
	if(conf)
	{		return true;	}
	else
	{		return false;	}

}
}

function confirmation2(text,url) {
	var answer = confirm(text)
	if (answer){ window.location = url; }

}
function confirmation(thisform)
{
	conf = confirm("Are you sure you want to decline the keyword because due to the following reason?");
	if(conf)
	{ return true;go('index.php?conf');	}
	else
	{ go('index.php?nonconf');	}
}
function droplist(value)
{
	if (value != "index.php?new_group=yes") { go(value); }
	else {enterText("Enter new group name","create website group named","index.php?new_group=","");}

}

function enterText(promptTitle,confirmText,url,defaultText)
{
	var answer = prompt (promptTitle,defaultText)
	if (answer != null)
	{confirmAction(confirmText+"\n\n "+answer,url+answer);}
}


 function confirmAction(actionDescription,url)
			{
            if(window.confirm("Are you sure you want "+actionDescription)){go(""+url+"");}
        	}

function checkemail(email)
{
	var testresults
	var str=email
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
	testresults=true
	else{
	testresults=false
	}
	return (testresults)
}
function confirmation(txt)
{
	conf = confirm(txt);
	if(conf)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function check_new_domain()
	{
		var obj=document.add_domain
		
		if(obj.new_domain.value == "your-domain.com")
		{
			alert("Please enter the domain name")
			obj.new_domain.focus();
			return false;
		}
		return true;
	}

function check_new_client_info()
	{
		var obj=document.step3
		
		
		if(obj.email.value=="")
		{
			alert("Please specify your email address. This will serve as your Rank Pay username in the future")
			obj.email.focus();
			return false;
		}
		if(obj.password.value=="")
		{
			alert("Please enter the password")
			obj.password.focus();
			return false;
		}
		if(obj.confirm_password.value=="")
		{
			alert("Please repeat the password")
			obj.confirm_password.focus();
			return false;
		}
		if(obj.password.value!=obj.confirm_password.value)
		{
			alert("Password and confirm password fields doesn't match")
			obj.confirm_password.focus();
			return false;
		}
		if(obj.cc_name.value=="")
		{
			alert("Please enter your name as it appers on the card")
			obj.cc_name.focus();
			return false;
		}

		if(obj.cc_number.value=="")
		{
			alert("Please enter your credit card number")
			obj.cc_number.focus();
			return false;
		}
		if(obj.cc_cvc.value=="")
		{
			alert("Please enter the CVC code which is located on the back of your card")
			obj.cc_number.focus();
			return false;
		}
		if(obj.terms_accepted.checked== false)
		{
			alert("Please read and accept service terms")
			obj.terms_accepted.focus();
			return false;
		}


		return true;
	}





