/* ************************************** Global Variables ************************************** */
var oAjax;
var param_CandidateID = 0;
var Candidate_Id = 0;
var param_RecruiterID = 0;
var Recruiter_Id = 0;
var Admin_Id = 0;
var param_AdminID = 0;
var AdminCounter = 60;
var CandidateCounter = 60; //no of times it'd try and wait for the session validation
var RecruiterCounter = 60; //no of times it'd try and wait for the session validation


/* **************************************************************************** */
document.write("<script type='text/javascript' src='js/prototype.js'> </script>");

/* ************************************** Global Functions ************************************** */
var adapter = '';
if ('undefined' != typeof ActiveXObject) {
	adapter = 'MS';
} else if ('undefined' != typeof document
		&& document.implementation
		&& document.implementation.createDocument
		&& 'undefined' != typeof DOMParser) {
	adapter = 'default';
}

/* *********************************************************************************************** */
//http://techpatterns.com/downloads/javascript_cookies.php
function SetCookie(name, value, expires, path, domain, secure) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime(today.getTime());

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if (expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date(today.getTime() + (expires));

	document.cookie = name + "=" + escape(value) +
((expires) ? ";expires=" + expires_date.toGMTString() : "") +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
((secure) ? ";secure" : "");
}
/*
function SetCookie (name,value,expires,path,domain,secure) 
{
alert("Cookie" +name + "=" + escape (value) +((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") +  ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""));
document.cookie = name + "=" + escape (value) +((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") +  ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
alert("cookie made") ;
}
*/
/*****************************************************************************************/
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}
/* **************************************************************************** */
// this deletes the cookie when called
function Delete_Cookie(name, path, domain) {
	//alert('hi');
	//alert(name + "=" +	( ( path ) ? ";path=" + path : "") +( ( domain ) ? ";domain=" + domain : "" ) +	";expires=Thu, 01-Jan-1970 00:00:01 GMT");
	if (readCookie(name))
		document.cookie = name + "=" + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	//alert('hello');
}
/****************************/

function getDomAdapter()/* Cross-browser compatablity xmldom*/
{

	switch (adapter) {
		case 'MS':
			return new (function () {
				this.createDocument = function () {/* createDocument method used to create object for XMLDOM*/

					var names = ["Msxml2.DOMDocument.6.0",
						"Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument",
						"MSXML.DOMDocument", "Microsoft.XMLDOM"];
					for (var key in names) {
						try {
							return new ActiveXObject(names[key]);
						} catch (e) { }
					}
					throw new Error('Unable to create DOMDocument');
				};
				this.serialize = function (doc) {/* serialize method used to retrive text xml from XMLDOM Object*/
					return doc.xml;
				};
				this.parseXml = function (xml) {/* parse Xml method  uesd to create XMLDOM object from text xml... have to pass xml string */
					var doc = this.createDocument();
					doc.async = false;
					if (xml != "")
						if (!doc.loadXML(xml)) {
							throw new Error('Parse error');
						}
					return doc;
				};
				this.getNodeValue = function (doc, nodename, index) {/* getNodeValue  method used to retrive value of single node... have to pass XMLDOM object and xpath to that node*/
					/*var node = doc.getNode(xpath);
					var value = node.text;*/
					/* modified by hitesh */
					try {
						var nodeval = doc.getElementsByTagName(nodename)[index].text;
						return nodeval;
					}
					catch (e) {
						return "";
					}
				};
				this.getNodeAttribute = function (doc, nodename, index, attribute) {
					try {
						var attribval = doc.getElementsByTagName(nodename)[index].getAttribute(attribute);
						return attribval;
					}
					catch (e) {
						return "";
					}
				};
				this.setNodeValue = function (node, value) {
					node.text = value;
					return node;
				};
				this.setNodeAttributeValue = function (doc, nodename, index, attribute, value) {
					try {
						var attribval = doc.getElementsByTagName(nodename)[index].setAttribute(attribute, value);
						return "";
					}
					catch (e) {
						return "";
					}
				};
				this.load = function (filename) {
					var doc = this.createDocument();
					doc.async = false;
					doc.load(filename);
					return doc;
				};

			})();
		case 'default':
			return new (function () {
				this.createDocument = function () {
					return document.implementation.createDocument("", "", null);
				};
				this.serialize = function (doc) {
					return new XMLSerializer().serializeToString(doc);
				};
				this.parseXml = function (xml) {
					var doc = new DOMParser().parseFromString(xml, "text/xml");
					if ("parsererror" == doc.documentElement.nodeName) {
						throw new Error('Parse error');
					}
					return doc;
				};
				this.getNodeValue = function (doc, nodename, index) {
					//var node = doc.getNode(xpath);
					//var value = node.singleNodeValue.textContent;
					/* modified by hitesh */
					try {
						var nodeval = doc.getElementsByTagName(nodename)[index].textContent;
						return nodeval;
					}
					catch (e) {
						return "";
					}
				};
				this.getNodeAttribute = function (doc, nodename, index, attribute) {
					try {
						var attribval = doc.getElementsByTagName(nodename)[index].getAttribute(attribute);
						return attribval;
					}
					catch (e) {
						return "";
					}
				};
				this.setNodeValue = function (node, value) {
					node.textContent = value;
					return node;
				};
				this.setNodeAttributeValue = function (doc, nodename, index, attribute, value) {
					try {
						var attribval = doc.getElementsByTagName(nodename)[index].setAttribute(attribute, value);
						return "";
					}
					catch (e) {
						return "";
					}
				};
				this.load = function (filename) {
					var doc = this.createDocument();
					doc.async = false;
					doc.load(filename);
					return doc;
				};
			})();
		default:
			throw new Error('Unable to select the DOM adapter');
	}
};
function addOption(docElement, optElement) {
	switch (adapter) {
		case 'MS':
			return docElement.add(optElement);
		case 'default':
			return docElement.add(optElement, null);
		default:
			throw new Error('Unable to select the DOM adapter');
	}

}

function getConsultantsTrackingURL() {
	var verified = document.getElementById("verifiedFlag").value;
	if (verified != '1') {
		document.write('<a style="color:#AAAAAA" href="#" id="trackingNav" onclick="alert(\'This functionality is available after you complete your profile and submit a resume.\');">Job Tracking</a>');
	}
	else {
		//var nonSecureLocation = readCookie('SERVERURL');
		//var secureLocation = nonSecureLocation.replace("https", "http") + '/ConsultantTracking.aspx';
		//var newLocation = 'document.location=\'' + secureLocation + '\'';
		document.write('<a href="ConsultantTracking.aspx" id="trackingNav">Job Tracking</a>');
	}
}

function getConsultantAccountURL() {
	/*if (readCookie('VERIFIED') != '1')
	{
	document.write('<a style="color:#AAAAAA" href="#" id="upgradeNav" onclick="alert(\'This functionality is available after you complete your profile and submit a resume.\');">Account Settings</a>');
	}
	else
	{
	var nonSecureLocation = readCookie('SERVERURL');
	var secureLocation = nonSecureLocation.replace("http", "https") + '/AccountSettings.aspx';
	var newLocation = 'document.location=\'' + secureLocation + '\'';
	document.write('<a href="javascript:' + newLocation + '" id="upgradeNav");">Account Settings</a>');
	}*/
	document.write('<a style="color:#AAAAAA" href="#" id="upgradeNav" onclick="alert(\'This is coming soon.\');">Account Settings</a>');
}

function getConsultantsSearchJobsURL() {
	var verified = document.getElementById("verifiedFlag").value;
	if (verified != '1') {
		document.write('<a style="color:#AAAAAA" href="#" id="searchNav" onclick="alert(\'This functionality is available after you complete your profile and submit a resume.\');">Search Jobs</a>');
	}
	else {
		//        var nonSecureLocation = readCookie('SERVERURL');
		//	    var secureLocation = nonSecureLocation.replace("https", "http") + '/ConsultantJobSearch.aspx';
		//	    var newLocation = 'document.location=\'' + secureLocation + '\'';
		document.write('<a href="ConsultantJobSearch.aspx" id="searchNav">Search Jobs</a>');
	}
}


function getConsultantSavedSearchesURL() {
	var verified = document.getElementById("verifiedFlag").value;
	if (verified != '1') {
		document.write('<a style="color:#AAAAAA" href="#" id="jobmatchNav" onclick="alert(\'This functionality is available after you complete your profile and submit a resume.\');">JobMatch<sup>TM</sup></a>');
	}
	else {
		//        var nonSecureLocation = readCookie('SERVERURL');
		//        var secureLocation = nonSecureLocation.replace("https", "http") + '/ConsultantJobMatch.aspx';
		//        var newLocation = 'document.location=\'' + secureLocation + '\'';
		document.write('<a href="ConsultantJobMatch.aspx" id="jobmatchNav">JobMatch<sup>TM</sup></a>');
	}
}

function checkConsultantsSearchOrTrackingAccess() {
	var verified = document.getElementById("verifiedFlag").value;
	if (verified != '1') {
		alert('This functionality is available after you edit you complete your profile and submit a resume.');
		//		var nonSecureLocation = readCookie('SERVERURL');
		//	    var secureLocation = nonSecureLocation.replace("https", "http") + '/ConsultantProfileHome.aspx';
		//	    var newLocation = 'document.location=\'' + secureLocation + '\'';
		location.href = 'ConsultantProfileHome.aspx';
	}
}

function getPleaseNoteContent() {
	var verified = document.getElementById("verifiedFlag").value;
	if (verified != '1') {
		document.write('<div class="sideBarNote"><h5>PLEASE NOTE</h5><p style="text-align:justify">Thank you for your interest in ERP-Consulting.com<br />We are evaluating your profile and will get back to you within 24 hours.<br />If your background and profile meet our site&#39;s standards, we will promptly add you to our system.<br />We reserve the right to remove any profiles that are either incomplete or contain excessive grammatical or structural errors.  Also, we require all consultants/candidates to have a minimum of 2 years of Canadian or US work experience, and a CURRENT valid work status for either the US or Canada.</p></div>');
	}
	else {
		document.write('');
	}
}

/*************/
function xInnerHTML(e, t) {
	if (adapter == 'MS')
		document.getElementById(e).innerHTML = t;
	else
		document.getElementById(e).update(t);
}

/* *************************************************************************************************************** */

function getXmlAttribute(eleMentId, attrName) {
	return document.getElementById("eleMentId").getAttribute("attrName")
}


function xTransform(xmlString, xslFile, sortKey) {
	try {
		var xsl = getDomAdapter().load(xslFile);
	}
	catch (e) {
		alert('error reading XSL file ' + e.message);
		return ""
	}

	try {
		if (adapter == "MS")
			var xml = getDomAdapter().parseXml(xmlString);
		else
			xml = xmlString; //firefox will get the XMLDOM
	}
	catch (e) {
		alert('error reading XML string ' + e.message);
		return ""
	}

	// code for IE
	if (window.ActiveXObject) {
		try {
			var xsldoc = new 
	ActiveXObject("Msxml2.FreeThreadedDOMDocument.3.0");
			var xslproc;
			xsldoc.async = false;
			xsldoc.load(xslFile);

			var xslt = new ActiveXObject("Msxml2.XSLTemplate.3.0");
			xslt.stylesheet = xsldoc
			xslproc = xslt.createProcessor();
			xmldoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
			xmldoc.loadXML(xmlString);
			xslproc.input = xmldoc;
			if (sortKey != "") {
				alert("sortKey " + sortKey);
				xslproc.addParameter("sortKey", "'USERNAME'");
			}
			xslproc.transform();
			ex = xmldoc.transformNode(xsldoc);
			return ex;
		}
		catch (e) {
			alert('error transforming the XML/XSL ' + e.message);
			return ""
		}
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument) {
		try {
			xsltProcessor = new XSLTProcessor();
			xsltProcessor.importStylesheet(xsl);

			if (sortKey != "") {
				alert("sortKey " + sortKey);
				XSLTProc.setParameter("", "sortKey", "USERNAME");
			}

			resultDocument = xsltProcessor.transformToFragment(xml, document);
			return resultDocument;
		}
		catch (e) {

			alert('error transforming the XML/XSL ' + e.message);
			return ""
		}
	}
	/**/
}

function loadXML(xmlString) {
	var oXML, oRequest;
	try {
		oXML = new ActiveXObject('Msxml2.DOMDocument');
	} catch (e) { oXML = false; }
	if (oXML) {
		//IE load XML document
		oXML.async = false;
		oXML.loadXML(xmlString);
		if (oXML.parseError.errorCode) {
			alert('error: ' + oXML.parseError.description);
			return false;
		}
	}
	if (!oXML) {
		//Mozilla load XML document
		try {
			oXML = document.implementation.createDocument("", "", null);
		} catch (e) { oXML = false; }
		if (oXML) {
			oXML.async = false;
			try {
				oXML.loadXML(xmlString);
			} catch (e) { oXML = false; }
		}
	}
	return oXML;
}

function loadXMLFile(sURL) {
	var oXML, oRequest;
	try {
		oXML = new ActiveXObject('Msxml2.DOMDocument');
	} catch (e) { oXML = false; }
	if (oXML) {
		//IE load XML document
		oXML.async = false;
		oXML.load(sURL);
		if (oXML.parseError.errorCode) {
			alert('error: ' + oXML.parseError.description);
			return false;
		}
	}
	if (!oXML) {
		//Mozilla load XML document
		try {
			oXML = document.implementation.createDocument("", "", null);
		} catch (e) { oXML = false; }
		if (oXML) {
			oXML.async = false;
			try {
				oXML.load(sURL);
			} catch (e) { oXML = false; }
		}
	}
	if (!oXML) {
		try {
			oRequest = new XMLHttpRequest();
			oRequest.open("GET", sURL, false);
			oRequest.send(null);
			oXML = oRequest.responseXML;
		} catch (e) { oXML = false; }
	}
	return oXML;
}

function setXSLParam(xsl, paramname, iValue) {
	var i, oNode;
	var oNodeList = xsl.documentElement.childNodes;

	for (i = 0; i < oNodeList.length; i++) {
		oNode = xmlNextNode(oNodeList, i);
		if (oNode.nodeName == 'xsl:param' && oNode.getAttribute('name') == paramname) {
			oNode.setAttribute('select', iValue);
			break;
		}
	}
}

function xmlNextNode(oNodeList, i) {
	var oNode;
	if (oNodeList.snapshotLength) {
		oNode = oNodeList.snapshotItem(i);
	} else {
		try {
			oNode = oNodeList.item(i);
		} catch (e) {
			alert('xmlxsl.js: xmlNextNode() not succesfull');
		}
	}
	return oNode;
}


function trnasformXML(oXML, oXSL) {
	var sHTML = '';
	//IE
	if (window.ActiveXObject) {
		try {
			sHTML = oXML.transformNode(oXSL);
			return sHTML;
		} catch (e) {
			alert('could not transform xml and xsl ' + e.message);
		}
	}
	//Mozilla
	if (document.implementation && document.implementation.createDocument) {
		var oProcessor = new XSLTProcessor();
		oProcessor.importStylesheet(oXSL);
		sHTML = oProcessor.transformToFragment(oXML, document);
		return sHTML;
	}
}


/* *************************************************************************************************************** */
function correctUrl(url) {

	if (url.toLowerCase().substring(0, 7) == 'http://')
		return url;
	if (url.toLowerCase().substring(0, 8) == 'https://')
		return url;
	return 'http://' + url;

}

/*************************/
function popUp(URL) {
	if (URL == "")
		return;
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,location=0,statusbar=0,resizable=1,menubar=0,width=720,height=640');");
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i = 0; i < data.length; i++) {
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
	},
	dataBrowser: [
		{ string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS: [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

