var popUp;
var popUpSearch;
var popUpDate;

// secure page
//if (top.location == this.location)
//	{ 
//	alert('Security breach!');
//	top.location = '/recruiterSoft/default.aspx'
//	}
			
function popupWindow(h, w, resize, scroll, url, popUpName, id)
{
	var height = h;
	var width = w;
	var offset;

	if (screen.Height > 600 || screen.Width > 800 ) 
 		offset = 175
	else
		offset = 25

	if (height == 0)
		height = new Number((screen.Height - offset))
	
	if (width == 0)
		width = new Number((screen.Width - offset))
	
	var top = new Number((screen.availHeight/2)-(height/2));	
	var left = new Number((screen.availWidth/2)-(width/2));	
		
	// supress popup if id is set to zero
	if (id == 0)
		alert("Not available");
	else
	{
		popUp = window.open(url,popUpName,"height="+height+",width="+width+",status=no,resizable="+resize+",scrollbars="+scroll+",top="+top+",left="+left);
		popUp.focus();
	}	
}


function popupWindowEnquirySearch(h, w, resize, scroll, url, popUpName)
{
	var height = h;
	var top;
	var width = w;
	var left;
	
	if (screen.Height > 600 || screen.Width > 800 ) 
 		offset = 175
	else
		offset = 25

	if (height == 0)
		height = new Number((screen.Height - offset))
	
	if (width == 0)
		width = new Number((screen.Width - offset))
	
	top = new Number((screen.availHeight/2)-(height/2));	
	left = new Number((screen.availWidth/2)-(width/2));	
	
	try {
		popUpEnquirySearch.focus();	
	}
	catch(err) {
		popUpEnquirySearch = window.open(url,"client","height="+height+",width="+width+",status=no,resizable="+resize+",scrollbars="+scroll+",top="+top+",left="+left);
	}
}

function popupWindowInvestorSearch(h, w, resize, scroll, url, popUpName)
{
	var height = h;
	var top;
	var width = w;
	var left;
	
	if (screen.Height > 600 || screen.Width > 800 ) 
 		offset = 175
	else
		offset = 25

	if (height == 0)
		height = new Number((screen.Height - offset))
	
	if (width == 0)
		width = new Number((screen.Width - offset))
	
	top = new Number((screen.availHeight/2)-(height/2));	
	left = new Number((screen.availWidth/2)-(width/2));	
	
	try {
		popUpInvestorSearch.focus();	
	}
	catch(err) {
		popUpInvestorSearch = window.open(url,"investor","height="+height+",width="+width+",status=no,resizable="+resize+",scrollbars="+scroll+",top="+top+",left="+left);
	}
}

function popupWindowDate(urlAdj, eleDate, SID)
{
	var height = 230;
	var width = 250;
	var txtDate;

	try {
		txtDate = eval(eleDate).value;
		
		popUpDate = window.showModalDialog(urlAdj+"SelectDate.aspx?SID=" + SID + "&Date="+txtDate+"&FE="+eleDate,"pDate","dialogHeight:245px;dialogWidth:245px;status:no;resizable:no;scrollbars:no;");
		
		if (popUpDate == 'cancel' || popUpDate == '' || popUpDate == undefined)
			popUpDate = '';
		else
			{
			eval(eleDate).value = popUpDate;
			eval(eleDate).focus();
			}
	}
	catch(err) {
		alert("Please try selecting the date again.");
	}
}

function popupWindowModal(h, w, resize, scroll, url)
{
	var height = h;
	var width = w;
	var popUpM;
	var offset;
	
	if (screen.Height > 600 || screen.Width > 800 ) 
 		offset = 175
	else
		offset = 25

	if (height == 0)
		height = new Number((screen.Height - offset))
	
	if (width == 0)
		width = new Number((screen.Width - offset))
		
	popUpM = window.showModalDialog(url,"popUpModal","dialogHeight:"+height+"px;dialogWidth:"+width+"px;status:no;resizable:"+resize+";scrollbars:"+scroll);
	
	if (popUpM == 'cancel' || popUpM == '' || popUpM == undefined)
		popUpM = '';
	else if (popUpM == 'refresh')
		window.location.reload();
	else
		window.location.href = popUpM;
}

function popupWindowModeless(h, w, resize, scroll, url)
{
	var height = h;
	var top = new Number((screen.availHeight/2)-(height/2));	
	var width = w;
	var left = new Number((screen.availWidth/2)-(width/3));	
	var popUpM;
	var offset;
	
	if (screen.Height > 600 || screen.Width > 800 ) 
 		offset = 175
	else
		offset = 25

	if (height == 0)
		height = new Number((screen.Height - offset))
	
	if (width == 0)
		width = new Number((screen.Width - offset))
	
		popUpM = window.showModelessDialog(url, window,"dialogHeight:"+height+"px;dialogWidth:"+width+"px;status:no;resizable:"+resize+";scrollbars:"+scroll+";top:"+top+";left:"+left);
	}

function popupClientSearch(SID, mode, fromFrameLeft, jobId)
{
	var height = 550;
	var top = new Number((screen.availHeight/2)-(height/2));	
	var width = 760;
	var left = new Number((screen.availWidth/2)-(width/2));	
	var PopUpSM;
	var urlPrefix = "";
	
	try {
		
		if (jobId == undefined)	jobId = 0;
		
		if (fromFrameLeft == false || fromFrameLeft == undefined)
			urlPrefix = "../";
		else
			urlPrefix = "UI/";
	
		PopUpSM = window.showModalDialog(urlPrefix + "search/ClientSearch.aspx?SID=" + SID + "&Open=yes&JobId=" + jobId + "&Type=C","popUpModal","dialogHeight:550px;dialogWidth:760px;status:no;resizable:yes;scrollbars:yes;top:"+top+";left:"+left);
		
		if (PopUpSM[0] == 'cancel' || PopUpSM[0] == '' || PopUpSM[0] == undefined)
			PopUpSM[0] = '';
		else
			{
			if (mode != 'load') {
				eval(_frmThis.hdnClientId).value = PopUpSM[0];
				eval(_frmThis.hdnClientName).value = PopUpSM[1];
				spnClientName.innerHTML = PopUpSM[1];
				}
			else {
				if (fromFrameLeft == false || fromFrameLeft == undefined) 
					window.location.href = "OptionClientContacts.aspx?SID=" + SID + "&ClientId=" + PopUpSM[0];
				else
					window.top.document.frames("FrameRight").document.frames("MainContent").location.href = "UI/clients/OptionClientContacts.aspx?SID=" + SID + "&ClientId=" + PopUpSM[0];
				}
			}
	}
	catch(err) {
		//error ocurred
		//alert(err);
	}
}

function popupPostcodePicker(txtLocs,hdnLocs,SID,parentId,type)
{
	var txtLoc;
	var txtDesc;

	try {
	
		txtLoc = eval(hdnLocs).value;
		
		popUpLocs = window.showModalDialog("../search/PostcodePicker.aspx?SID=" + SID + "&ParentId="+parentId+"&Type="+type+"&Ids="+txtLoc,"Picker","dialogHeight:500px;dialogWidth:700px;status:no;resizable:no;scrollbars:no;");
		
		if (popUpLocs != undefined) {
		
			if (popUpLocs[0] == 'cancel' || popUpLocs[0] == '' || popUpLocs[0] == undefined)
				popUpLocs = '';
			else
				{
				if (popUpLocs[0] == 'none') { 
					popUpLocs[0] = '';
				}
				eval(txtLocs).value = popUpLocs[0];
				eval(hdnLocs).value = popUpLocs[1];
				}
		}
	}
	catch(err) {
		alert("Please try selecting the postcodes again.");
	}
}

function OptionsOff() 
{

	top.document.frames("FrameLeft").divOptionsE.style.display = "none";
	top.document.frames("FrameLeft").divOptionsI.style.display = "none";
	top.document.frames("FrameLeft").divOptionsO.style.display = "none";
}

function OnlyDigits()
{
	
	if (window.event.keyCode < 48 || window.event.keyCode > 57) 
	{
		window.event.keyCode = 0; 
		return false;
	}	
	else
		return true;
	
}

function ShowHelp() {
	
	if (divHelp.style.display == "none") 
		{
		divHelp.style.display = "inline";
		window.scrollBy(600,0);
		}
	else
		{	
		divHelp.style.display = "none";
		}
}

function ViewEmail(EmailId, EmailKey) {
		
	popupWindow(500, 600, "yes", "yes", "../email/ViewEmail.aspx?EmailId=" + EmailId + "&EmailKey=" + EmailKey)
				
	}
	
function AddIV(JobId, CandId, Ref) {
		
	popupWindowModal(550, 600, "no", "yes", "../calendar/InterviewDetails.aspx?Ref=" + Ref + "&InterviewId=0&JobId=" + JobId + "&CandId=" + CandId)
				
	}
	
function IVF(InterviewId) {

	if (confirm("Click OK to mark this interview as complete or Cancel to add interview follow up notes.")) 
		document.location.href = "../calendar/EventComplete.aspx?InterviewId=" + InterviewId;
	else
		popupWindowModal(500, 550, "no", "yes", "../calendar/InterviewFollowUp.aspx?InterviewId=" + InterviewId)
				
	}
	
function AddNote(SID, ParentId, Type, Ref, SubId) {
	
	if (SubId == undefined) SubId == 0;
	
	if (ParentId == undefined || ParentId == 0)
		alert("Please select one candidate.");
	else															
		popupWindowModal(300, 510, "no", "no", "../notes/NoteDetails.aspx?SID=" + SID + "&NoteId=0&Type=" + Type + "&Ref=" + Ref + "&ParentId=" + ParentId + "&SubId=" + SubId)
				
	}
	
function AddAnEvent(SID,Hour,Ref, Dis, CandId) {
	
	if (CandId == 0) 															
		popupWindowModal(500, 510, "no", "no", "../calendar/EventDetails.aspx?SID=" + SID + "&Hour=" + Hour + "&EventId=0&Dis=" + Dis + "&Ref=" + Ref);
	else
		popupWindowModal(500, 510, "no", "no", "../calendar/EventDetails.aspx?SID=" + SID + "&Hour=" + Hour + "&EventId=0&hdnCandidateId=" + CandId + "&Dis=" + Dis + "&Ref=" + Ref);
	}
	
function EditAnEvent(SID, EventId, Ref, CandId) {

	if (confirm("Click OK to mark this event as complete or Cancel to edit this event.")) 
			document.location.href = "../calendar/EventComplete.aspx?SID=" + SID + "&EventId=" + EventId;
	else
			popupWindowModal(500, 510, "no", "no", "../calendar/EventDetails.aspx?SID=" + SID + "&EventId=" + EventId + "&hdnCandidateId=" + CandId + "&Ref=" + Ref);
	}

function ViewCR(JobId) {
																
	popupWindowModal(500, 570, "no", "yes", "ChangeRequests.aspx?JobId=" + JobId)
				
	}	

function ToggleOtherReason(prefix) {
	
	try {
		if (document.all.item(prefix + "chkRepo").checked == true)
			{
				document.all.item(prefix + "txtOtherReason").style.background = "#ece9d8";
				document.all.item(prefix + "txtOtherReason").disabled = true;
				document.all.item(prefix + "txtOtherReason").value = "";
			}
		else
			{
				document.all.item(prefix + "txtOtherReason").style.background = "#ffffff";
				document.all.item(prefix + "txtOtherReason").disabled = false;
			}
		}
	catch(err) {
	alert(err)
	}
		
}

function ToggleOtherReasonC(prefix) {
	
	try {
		if (document.all.item(prefix + "chkRepo").checked == true)
			{
				document.all.item(prefix + "txtOtherReason").style.display = "none";
				divReason.style.display = "none";
			}
		else
			{
				document.all.item(prefix + "txtOtherReason").style.display = "inline";
				divReason.style.display = "inline";
			}
		}
	catch(err) {
	alert(err)
	}
		
}

function SetGender(title,gender) {

	try {	
	
		var opt = document.all.item(title).value;

		switch(opt)
		{
			case 'Miss': { document.all.item(gender).options(1).selected = true; break; }
			case 'Mr': { document.all.item(gender).options(0).selected = true; break; }
			case 'Mrs': { document.all.item(gender).options(1).selected = true; break; }
			default: document.all.item(gender).options(0).selected = true;
		}
		
	}
				catch(err) {
				// do nothing 			
				}	
}


function isNumeric(val) {
	return (parseFloat(val,10) == (val*1));
}