function checkAll(obj1,obj2)
{
	var login=document.getElementById(obj1);
	var pwd = document.getElementById(obj2);
	
	if (checkEmpty(login)==false && checkEmpty(pwd)==false)
	{
		login.focus();
		window.alert(Email_Check_Alert + "\n"+ Pswd_Check_Alert );
		
		return false;
	}	
	/*else if ((checkEmpty(pwd)==false) && (!EvaluateMail(login)==false))
	{
		window.alert(EmailValid_Check_Alert +"\n"+Pswd_Check_Alert);
		return false;
	}*/
	else if (checkEmpty(login)==false)	
	{
		login.focus();
		alert(Email_Check_Alert);
		return false;
	}
	else if (!EvaluateMail(login.value))
	{
		login.focus();
		login.select();
		alert(EmailValid_Check_Alert);
		return false;
	}	
	else if (checkEmpty(pwd)==false)
	{
		pwd.focus();
		alert(Pswd_Check_Alert);
		return false;
	}
	
	return true;
}

function newUser(objEmail,ObjPasswd,ObjConfPasswd)
{
	var email=document.getElementById(objEmail);
	var passwd=document.getElementById(ObjPasswd);
	var confpasswd=document.getElementById(ObjConfPasswd);
	
	if(checkEmpty(email)==false && checkEmpty(passwd)==false && checkEmpty(confpasswd)==false)
	{
		email.focus();
		window.alert(Email_Check_Alert +"\n"+Pswd_Check_Alert +"\n" + Pswd_Confirmation_Check_Alert); 
		return false;
	}
	/*else if ((checkEmpty(passwd)==false) && (EvaluateMail(email.value)==false))
	{
		window.alert(EmailValid_Check_Alert +"\n"+Pswd_Check_Alert);
		return false;
	}*/
	else if(checkEmpty(email)==false)
	{
		email.focus();
		window.alert(Email_Check_Alert);
		return false;
	}	
	else if(!EvaluateMail(email.value))
	{
		email.focus();
		email.select();
		window.alert(EmailValid_Check_Alert);
		return false;
	}
	else if(checkEmpty(passwd)==false)
	{
		passwd.focus();
		window.alert(Pswd_Check_Alert);
		return false;
	}
	else if(passwd.value.length < 6)
	{		
		passwd.focus();
		window.alert(Pswd_Length_Btbn);
		return false;
	}
	else if(checkEmpty(confpasswd)==false)
	{
		confpasswd.focus();
		window.alert(Confirmation_Pswd_Alert);
		return false;
	}
	else if(confpasswd.value.length < 6)
	{		
		confpasswd.focus();
		window.alert(Confirmation_Pswd_Length_Check_Alert);
		return false;
	}
	else if(passwd.value != confpasswd.value)
	{
		confpasswd.focus();
		window.alert(Confirm_Pswd_Donot_Match);
		return false;
	}
	return true;
}

function FocusatStart(objtxtLogin)
{
	if (document.getElementById(objtxtLogin)!=null)
	{
		var login=document.getElementById(objtxtLogin);
		focus(login);
	}
}

//FromValidation.js

function focus(ctrl)
{
	document.getElementById(ctrl.id).focus();
}

function Fixfocus(objPwdMessage,objMsgLoginFailed,objSubmit,event) 
{
	var isNS4 = (navigator.appName=="Netscape")?1:0;
	if(document.getElementById(objPwdMessage) != null)
		document.getElementById(objPwdMessage).innerText="";
	if(document.getElementById(objMsgLoginFailed) != null)
		document.getElementById(objMsgLoginFailed).innerText="";
	
	if(!isNS4)
	{
	  
		if (event.keyCode==13)
		{
			document.getElementById(objSubmit).focus();
		}
	}
	else
	{
	  
		if (event.which==13)
		{			
			document.getElementById(objSubmit).focus();
		}
	}
}

function ClearLabel(objPwdMessage,objMsgLoginFailed,objLogin,event)
{	
	var isNS4 = (navigator.appName=="Netscape")?1:0;
	if(document.getElementById(objPwdMessage) != null)
		document.getElementById(objPwdMessage).innerText="";
	if(document.getElementById(objMsgLoginFailed) != null)
		document.getElementById(objMsgLoginFailed).innerText="";
	
	//alert(isNS4);
	
	if(!isNS4)
	{
		if (event.keyCode==13)
		{
			document.getElementById(objLogin).focus();
		}
	}
	else
	{
		if (event.which ==13)
		{
			document.getElementById(objLogin).focus();
		}
	}
}

function ClearFields(objPwdMessage)
{
	//document.getElementById("lblPwdMessage").innerHTML="";
	if (document.getElementById(objPwdMessage)!=null)
		document.getElementById(objPwdMessage).innerText="";
}

function register(objEmail,ObjPasswd,ObjConfPasswd,objForm,applicationName,applicationVersion,useragent,doCheck)
{
	
	var strFormName;
	if (newUser(objEmail,ObjPasswd,ObjConfPasswd)==true)
	{
	    if(document.getElementById('hdnLogin') != null)
			document.getElementById('hdnLogin').value='register';
		//alert(document.getElementById('hdnLogin').value);
		strFormName=document.getElementById(objForm);
		//alert(strFormName);
		if(doCheck) //BROWSER CHECK SET TO TRUE
		{
			//if(browserCheck(applicationName,applicationVersion,useragent))
			  strFormName.submit();
		}
		else
			strFormName.submit();
		
	}
}
function browserCheck(applicationName,applicationVersion,useragent)
{
	temp=applicationVersion.split("MSIE")
	var version=parseFloat(temp[1])
	if (applicationName !="Microsoft Internet Explorer" || version <=5.5)
	{
		alert("We are sorry but to register as an advertiser or an affiliate and to use all the features you must use a PC and Internet Explorer version 5.5 or newer.Click OK to Continue");
		return false;
	}
	else if(useragent.indexOf('Opera')!=-1)
	{
		alert("We are sorry but to register as an advertiser or an affiliate and to use all the features you must use a PC and Internet Explorer version 5.5 or newer.Click OK to Continue");
		return false;
	
	}
	return true;
}
function login(obj1,obj2,objForm,applicationName,applicationVersion,useragent,doCheck)
{
	var strFormName;
	if (checkAll(obj1,obj2)==true)
	{
	    if(document.getElementById('hdnLogin') != null)
			document.getElementById('hdnLogin').value='login';
		//alert(document.getElementById('hdnLogin').value);
		strFormName=document.getElementById(objForm);
		//alert(strFormName);
		/*if(doCheck) //BROWSER CHECK SET TO TRUE
		{
			if(browserCheck(applicationName,applicationVersion,useragent))
			  strFormName.submit();
		}
		else*/
			strFormName.submit();
	}
}

function openMail()
{
	window.open("http://www.hotmail.com");
}

function changePassword(objOldPasswd,ObjPasswd,ObjConfPasswd)
{
	var oldpasswd=document.getElementById(objOldPasswd);
	var newpasswd=document.getElementById(ObjPasswd);
	var confpasswd=document.getElementById(ObjConfPasswd);
	
	if(checkEmpty(oldpasswd)==false && checkEmpty(newpasswd)==false && checkEmpty(confpasswd)==false)
	{
		oldpasswd.focus();
		window.alert(Old_Pswd_Alert +"\n"+ New_Pswd_Alert+"\n"+Confirmation_Pswd_Alert); 
		return false;
	}
	else if(checkEmpty(oldpasswd)==false)
	{
		oldpasswd.focus();
		window.alert(Old_Pswd_Alert);
		return false;
	}
	else if(oldpasswd.value.length < 6 || oldpasswd.value.length >15)
	{		
		oldpasswd.focus();
		window.alert(Pswd_Length_Btbn);
		return false;
	}
	else if(checkEmpty(newpasswd)==false)
	{
		newpasswd.focus();
		window.alert(New_Pswd_Alert);
		return false;
	}
	else if(newpasswd.value.length < 6 || newpasswd.value.length >15)
	{		
		newpasswd.focus();
		window.alert(Pswd_Length_Btbn);
		return false;
	}
	else if(oldpasswd.value==newpasswd.value)
	{
		newpasswd.focus();
		window.alert(Old_New_Pswd_SameCheck_Alert +"\n Please re-enter");
		return false;		
	}
	else if(checkEmpty(confpasswd)==false)
	{
		confpasswd.focus();
		window.alert("-Please enter Confirmation Password");
		return false;
	}
	else if(confpasswd.value.length < 6 || confpasswd.value.length >15)
	{		
		confpasswd.focus();
		window.alert(Pswd_Length_Btbn);
		return false;
	}
	else if(newpasswd.value != confpasswd.value)
	{
		confpasswd.focus();
		window.alert(Confirm_Pswd_Donot_Match);
		return false;
	}
	return true;
}

function checkPassword(objOldPasswd,ObjPasswd,ObjConfPasswd,objForm)
{
	var strFormName;
	if (changePassword(objOldPasswd,ObjPasswd,ObjConfPasswd)==true)
	{
		document.getElementById('hdnChangePassword').value='changed';
		//alert(document.getElementById('hdnLogin').value);
		strFormName=document.getElementById(objForm);
		//alert(strFormName);
		strFormName.submit();
	}
}

//FUNCTION TO FILL THE REGISTRATION FIELDS FROM CUSTOMERHOMEPAGE
function FillRegisterFields(objEmail,ObjPassword,objConfirmPassword, objHdnEmail, objHdnPassword)
{
	var Email = document.getElementById(objEmail);
	var Password = document.getElementById(ObjPassword);
	var ConfirmPassword = document.getElementById(objConfirmPassword);
	var HomePageEmail = document.getElementById(objHdnEmail);
	var HomePagePassword = document.getElementById(objHdnPassword);
	if(HomePageEmail != null && HomePagePassword != null && HomePageEmail.value != null && HomePagePassword.value != null && HomePageEmail.value != "" && HomePagePassword.value != "")
	{
		Email.value = HomePageEmail.value;
		Password.value = HomePagePassword.value;
		ConfirmPassword.focus();
		HomePageEmail.value = "";
		HomePagePassword.value = "";
	}
	
}



var ModalDialogWindow;
var ModalDialogInterval;
var ModalDialog = new Object;

ModalDialog.value = '';
ModalDialog.eventhandler = '';

function ModalDialogMaintainFocus()
{
try
{
	if (ModalDialogWindow.closed)
	{
		window.clearInterval(ModalDialogInterval);
		eval(ModalDialog.eventhandler);
		return;
	}
	ModalDialogWindow.focus();
}
catch (everything) {   }
}

function ModalDialogRemoveWatch()
{
	ModalDialog.value = '';
	ModalDialog.eventhandler = '';
}

function CloseForm(strResult,objFrm)
{
 
  if(document.getElementById('hdnRoleFor') != null )
  {
	if(document.getElementById('hdnRoleFor').value != 'lost')
    {
      if(strResult != 'CANCEL')
       {
		document.getElementById('hdnRoleFor').value = strResult;
		document.getElementById(objFrm).submit(); 
	   }
	  else
	   {
	   document.getElementById('loginpanel').className = 'logboxinnerh6c';
	   document.getElementById('rolepanel').className = 'hide';
	   return false;
	   }	    	
     }
     else
      {
        var role="";
        if(strResult == 'AFFAGENT')
           role="agt";
        else if(strResult == 'AFFILIATE')   
          role="aff";
        else if(strResult == 'CANCEL')     
         {
           document.getElementById('loginpanel').className = 'logboxinnerh6c';
		   document.getElementById('rolepanel').className = 'hide';
		   document.getElementById('hdnRoleFor').value ="";
           return false;
         } 
        document.getElementById('loginpanel').className = 'logboxinnerh6c';
		document.getElementById('rolepanel').className = 'hide';
		document.getElementById('hdnRoleFor').value=""; 
        LostPassword(role,'hdnSiteUrl');     
      }
   }
}

function YesNoCancel(BodyText,EventHandler,objResult, objForm)
{
	var Buttons='';
	Buttons = '<a  class="affiliate" href=javascript:CloseForm("AFFILIATE","'+ objResult +'","'+ objForm + '");></a>  ';
	Buttons += '<a  class="affiliateagent" href=javascript:CloseForm("AFFAGENT","'+ objResult +'","'+ objForm + '");></a>  ';
	Buttons += '<a class="cancel" href=javascript:CloseForm("CANCEL","'+ objResult +'","'+ objForm + '");></a>  ';
	ModalDialogShow("SelectRole",BodyText,Buttons,EventHandler);
}

function YesNoCancelReturnMethod()
{
	ModalDialogRemoveWatch();
}

function loginForAffiliate(obj1,obj2,objForm,objResult,applicationName,applicationVersion,useragent)
{

	document.getElementById('hdnLogin').value='login';
	if (checkAll(obj1,obj2)==true)
	{
	temp=applicationVersion.split("MSIE");
	var version=parseFloat(temp[1]);
	/*if (applicationName !="Microsoft Internet Explorer" || version <=5.5)
	{
		alert("We are sorry but to register as an advertiser or an affiliate and to use all the features you must use a PC and Internet Explorer version 5.5 or newer.Click OK to Continue");
		return;
	}
	else if(useragent.indexOf('Opera')!=-1)
	{
		alert("We are sorry but to register as an advertiser or an affiliate and to use all the features you must use a PC and Internet Explorer version 5.5 or newer.Click OK to Continue");
		return;
	
	}*/
		if(document.getElementById('loginpanel') != null )
		 {
		   document.getElementById('loginpanel').className = 'hide';
		   if(document.getElementById('rolepanel') != null )
			document.getElementById('rolepanel').className = 'rolepanel';
		 }
	}
	
}



function GoToLostPassword(objSaver,objAdvertiser,objAffiliate,objResult)
{
	var Saver = document.getElementById(objSaver);
	var Advertiser = document.getElementById(objAdvertiser);
	var Affiliate = document.getElementById(objAffiliate);
	
	if(Saver.checked)
	{
		LostPassword('cust');		
	}
	if(Advertiser.checked)
	{
		LostPassword('adv');
	}
	if(Affiliate.checked)
	{
		AffiliateLostPassword();
	}
}

function AffiliateLostPassword()
{
	if(document.getElementById('loginpanel') != null )
		 {
		   document.getElementById('loginpanel').className = 'hide';
		   if(document.getElementById('rolepanel') != null )
				document.getElementById('rolepanel').className = 'rolepanel';
		   document.getElementById('hdnRoleFor').value ='lost'; 	
		 }
	
}