var IFrameObj; // our IFrame object

function cleanString(str)
{
 str = unescape( str.toString() );
 str = str.replace(/</g, '&lt;');
 str = str.replace(/>/g, '&gt;');
 return str;
 }

function setURL(countryID, showStates, str, company, companyType)
{
 var URL;

 switch(str) {
 case '1' : URL = 'http://www.jobxjobs.com/widgets/VARSITY/DomSearchVarsity.html';
 break;
 case '2' : URL = 'http://www.jobx.co.nz/widgets/DomSearch1.aspx';
 break;
 case '3' : URL = 'http://www.jobx.co.nz/widgets/DomSearch2.aspx';
 break;
 case '4' : URL = 'http://www.jobx.co.nz/widgets/DomSearch3.aspx';
 break;
 case '10' : URL = 'http://www.jobxjobs.com/widgets/hbb/DomSearchGeekzone.html';
 break;
 default : URL = 'http://www.jobx.co.nz/widgets/DomSearch.aspx';
 }
 URL = URL + '?countryID=' + countryID;
 URL = URL + '&showStates=' + showStates;

 if (companyType == 1)
 {
	 URL = URL + '&recruiterID=' + company;
 }
 else if (companyType == 2)
 {
	URL = URL + '&companyID=' + company;
 }
 return URL;
 }

function setWidth(str)
{
 switch(str) {
 case '1' : return 550;
 break;
 case '2' : return 470;
 break;
 case '3' : return 415;
 break;
 case '4' : return 140;
 break;
 case '5' : return 922;
 break;
 default : return 275;
 }
}

function setHeight(str)
{
 switch(str) {
 case '1' : return 300;
 break;
 case '2' : return 205;
 break;
 case '3' : return 255;
 break;
 case '4' : return 515;
 break;
  case '5' : return 246;
 break;
 default : return 270;
 }
}


function callToServer() {
 if (!document.createElement) {return true};
 var IFrameDoc;
 var URL;


 var countryID;

 if (window.jobX_Country_id)
 {
	countryID = window.jobX_Country_id;
 }
 else
 {
	countryID = 1;
 }

 var showStates;

 if (window.jobX_Show_States != null)
 {
	showStates = window.jobX_Show_States;
 }
 else
 {
	showStates = true;
 }

 if (window.jobX_Recruiter_id)
 {
	URL = setURL(countryID, showStates, cleanString(window.jobX_search_style), cleanString(window.jobX_Recruiter_id), 1);
 
	if (window.jobX_Profession_id)
	{
		URL = URL + '&professionID=' + cleanString(window.jobX_Profession_id);
	}
 }
 else if (window.jobX_Company_id)
 {
	URL = setURL(countryID, showStates, cleanString(window.jobX_search_style), cleanString(window.jobX_Company_id), 2);
	
	if (window.jobX_Profession_id)
	{
		URL = URL + '&professionID=' + cleanString(window.jobX_Profession_id);
	}
 }
 else
 {
	URL = setURL(countryID, showStates, cleanString(window.jobX_search_style), '', 3);
	if (window.jobX_Profession_id)
	{
		URL = URL + '&professionID=' + cleanString(window.jobX_Profession_id);
	}
 }

 var width = setWidth(cleanString(window.jobX_search_style));
 var height = setHeight(cleanString(window.jobX_search_style));

 if (!IFrameObj && document.createElement) {
 // create the IFrame and assign a reference to the
 // object to our global variable IFrameObj.
 // this will only happen the first time
 // callToServer() is called
 try {
 var tempIFrame=document.createElement('iframe');

 tempIFrame.setAttribute('id','RSIFrame');
 tempIFrame.setAttribute('frameBorder', '0');
 tempIFrame.setAttribute('src', URL);
 tempIFrame.setAttribute('scrolling', 'no');
 tempIFrame.setAttribute('tabIndex', '-1');
 tempIFrame.style.border ='0px';
  tempIFrame.style.padding ='0px';
   tempIFrame.style.margin ='0px';
 tempIFrame.style.top ='0px';
 tempIFrame.style.left ='0px';
 tempIFrame.style.width= width + 'px';
 tempIFrame.style.height= height + 'px';

 var temElement = document.getElementById('JobXWidgetSearch');

 IFrameObj = temElement.appendChild(tempIFrame);

 if (document.frames) {
 // this is for IE5 Mac, because it will only
 // allow access to the document object
 // of the IFrame if we access it through
 // the document.frames array
 IFrameObj = document.frames['RSIFrame'];

 }
 } catch(exception) {
 // This is for IE5 PC, which does not allow dynamic creation
 // and manipulation of an iframe object. Instead, we will fake
 // it up by creating our own objects.
 iframeHTML='\<iframe id="RSIFrame" frameborder="0" scrolling="no" ';
 iframeHTML+='src="' + URL + '"';
 iframeHTML+=' style="';
 iframeHTML+='border:0px;';
 iframeHTML+='padding:0px;';
 iframeHTML+='margin:0px;';
 iframeHTML+='width:' + width + 'px;';
 iframeHTML+='height:' + height + 'px;';
 iframeHTML+='"><\/iframe>';
 document.body.innerHTML+=iframeHTML;

 IFrameObj = new Object();
 IFrameObj.document = new Object();
 IFrameObj.document.location = new Object();
 IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
 IFrameObj.document.location.replace = function(location) {
 this.iframe.src = location;
 }
 }
 }

 if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
 // we have to give NS6 a fraction of a second
 // to recognize the new IFrame
 setTimeout('callToServer()',10);
 return false;
 }


 //IFrameDoc.location.replace(URL);
 return false;
}

callToServer();
