// JavaScript Document
//--------------------------------------------------------------- Start Of Ajax Function -----------------------------------------------------------------------
var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid)
{
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
	{
		document.getElementById(containerid).innerHTML=page_request.responseText
	}
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
	fileref=document.createElement('script')
	fileref.setAttribute("type","text/javascript");
	fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
	fileref=document.createElement("link")
	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");
	fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}
//--------------------------------------------------------------- End Of Ajax Function -----------------------------------------------------------------------


// ------------------------------------------------------------------ POPUP WINDOW ---------------------------------------------------------------------------
var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);
var calunit=ns? "" : "px"

function PopUP(dv)
{
	if(!ns && !ie && !w3) return;
	if(ie)		adDiv=eval('document.all.'+dv+'.style');
	else if(ns)	adDiv=eval('document.layers["'+dv+'"]');
	else if(w3)	adDiv=eval('document.getElementById("'+dv+'").style');

    if (ie||w3)
	{
        adDiv.visibility="visible";
		adDiv.display ="block";
	}
    else
	{
        adDiv.visibility ="show";
	}
	if (ie)
	{
		documentWidth  =truebody().offsetWidth/2+truebody().scrollLeft-20;
		documentHeight =truebody().offsetHeight/2+truebody().scrollTop-20;
	}	
	else if (ns)
	{
		documentWidth=window.innerWidth/2+window.pageXOffset-20;
		documentHeight=window.innerHeight/2+window.pageYOffset-20;
	} 
	else if (w3)
	{
		documentWidth=self.innerWidth/2+window.pageXOffset-20;
		documentHeight=self.innerHeight/2+window.pageYOffset-20;
	} 
	adDiv.left=documentWidth-375+calunit;
	adDiv.top =documentHeight-120+calunit;
	
}
function closePopUP()
{
	if (ie||w3)
	adDiv.display="none";
	else
	adDiv.visibility ="hidden";
}

function truebody()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
// --------------------------------------------------------------- END OF POPUP WINDOW -----------------------------------------------------------------------

// ---------------------------------------------------------------- email pass textbox form ------------------------------------------------------------------
function callPstLogInfo(e, id, eml, ps)
{
	emlbx = document.getElementById(eml)
	pswbx = document.getElementById(ps)
	if (e == '')
	{
		if (id == 'both')
		{
			if (emlbx.value != "")
			{
				emlbx.style.background = '#FFFFFF'
			}
			else
			{
				emlbx.style.background = '#FFFFFF url(images/psemlbg.gif) left center no-repeat'
			}
			
			if (pswbx.value != "")
			{
				pswbx.style.background = '#FFFFFF'
			}
			else
			{
				pswbx.style.background = '#FFFFFF url(images/pspswbg.gif) left center no-repeat'
			}
		}
		if (id == 'eml')
		{
			if (emlbx.value != "")
			{
				emlbx.style.background = '#FFFFFF'
			}
			else
			{
				emlbx.style.background = '#FFFFFF url(images/psemlbg.gif) left center no-repeat'
			}
		}
		if (id == 'psw')
		{
			if (pswbx.value != "")
			{
				pswbx.style.background = '#FFFFFF'
			}
			else
			{
				pswbx.style.background = '#FFFFFF url(images/pspswbg.gif) left center no-repeat'
			}
		}		
	}
	if (e == 'click')
	{
		if (id == "eml")
		{
			emlbx.style.background = '#FFFFFF'
		}
		if (id == "psw")
		{
			pswbx.style.background = '#FFFFFF'
		}
	}
}
// ----------------------------------------------------------- End of email pass textbox form ----------------------------------------------------------------
// ----------------------------------------------------------------- Other Functions -------------------------------------------------------------------------
function loadTodayDiv(typ)
{
	if (typ != "")
	{
		var url = "bizproc.asp"
		switch (typ)
		{
			case "T.Req":
				url = url+"?type=5"
				document.getElementById('todayreq').innerHTML = '<div style="display:block;  padding:20px; text-align:center; font:normal 14px verdana;"><img src="images/loading.gif"><br><br>Loading...</div>'
				ajaxpage(url, 'todayreq')
				break;
			
			case "T.Hot":
				url = url+"?type=6"
				document.getElementById('todayhot').innerHTML = '<div style="display:block;  padding:20px; text-align:center; font:normal 14px verdana;"><img src="images/loading.gif"><br><br>Loading...</div>'
				ajaxpage(url, 'todayhot')
				break;
				
			default:
				alert("There was an error occured while loading this page! SOme functions may not be showed correctly!\nKindly refresh this page again to solve this!");
				break;
		}
	}
}


function PopUpDiv(typ, dv)
{
	var url = "bizproc.asp";
	var msg = "";
	//alert(typ)
	if (typ != "")
	{
		switch (typ)
		{
			case "Post.Req":
				url = url+"?type=1";
				msg = "<br><img src='images/loading.gif' alt='loading image'><br><br>Thank you for your patience!<br>The Requirement posting form is loading..."
				actmsg = "";
				break;
				
			case "Post-Hot":
				url = url+"?type=2";
				msg = "<br><img src='images/loading.gif' alt='loading image'><br><br>Thank you for your patience!<br>The Hotlist posting form is loading..."
				actmsg = "";
				break;

			case "Show.Hotlist-Skill":
				url = url+"?type=7";
				msg = "<br><img src='images/loading.gif' alt='loading image'><br><br>Please wait.<br>The skills are loading..."
				actmsg = '<font style="font:bold 17px verdana; padding:5px; color:#a93232;">Search Hotlist by skills</font>';
				break;
				
			default:
				url = "";
				msg = "";
				actmsg = "";
				break;
		}
		if (url != "")
		{
			PopUP(dv);
			document.getElementById('actstatdiv').innerHTML = actmsg;
			document.getElementById('contentdiv').innerHTML = msg;
			ajaxpage(url, 'contentdiv')
		}
		else
		{
			alert("1- Oops! There was an error occured! Please Check again (or) Reload this page again!")	
			closePopUP()
		}
	}
	else
	{
		alert("2- Oops! There was an error occured! Please Check again (or) Reload this page again!")
		closePopUP()
	}
}

function ValidatePostReq()

{
	var pform = document.postreq;
	var emailExp = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	var vchk = false;
	
	if (pform.req_title.value == "")
	{
		pform.req_title.style.border = '2px solid #FF0000';
		pform.req_title.focus();
		document.getElementById('err_reqtitle').innerHTML = 'Without Title, we cannot post your Requirement!';
		vchk = false;
	}
	else if ((pform.req_title.value.length < 5) || (pform.req_title.value.length > 50))
	{
		pform.req_title.style.border = '2px solid #FF0000';
		pform.req_title.focus();
		document.getElementById('err_reqtitle').innerHTML = 'Please revise your title! It should be between 5 to 50.'
		vchk = false;
	}
	else
	{
		pform.req_title.style.border = '1px solid #bcd3e8';
		document.getElementById('err_reqtitle').innerHTML = '';
		if (vchk == true) { vchk = true; }
	}
	
	if (pform.req_state.value == "")
	{
		pform.req_state.style.color = '#FF0000';
		pform.req_state.focus();
		document.getElementById('err_reqstate').innerHTML = 'Please Select your State!'
		vchk = false;
	}
	else
	{
		document.getElementById('err_reqstate').innerHTML = '';
		pform.req_state.style.color = '#999999';
		if (vchk == true) { vchk = true; }
	}
	
	if (pform.req_city.value == "")
	{
		pform.req_city.style.border = '2px solid #FF0000';
		pform.req_city.focus();
		document.getElementById('err_reqcity').innerHTML = 'Please provide your City!';
		vchk = false;
	}
	else if (pform.req_city.value.length > 50)
	{
		pform.req_city.style.border = '2px solid #FF0000';
		pform.req_city.focus();
		document.getElementById('err_reqcity').innerHTML = 'Revise your City!';
		vchk = false;
	}
	else
	{
		document.getElementById('err_reqcity').innerHTML = '';
		pform.req_city.style.border = '1px solid #bcd3e8';
		if (vchk == true) { vchk = true; }
	}
	
	if (pform.req_desc.value == "")
	{
		pform.req_desc.style.border = '2px solid #FF0000';
		pform.req_desc.focus();
		document.getElementById('err_reqdesc').style.color = '#FF0000';
		vchk = false;
	}
	else
	{
		pform.req_desc.style.border = '1px solid #bcd3e8';
		document.getElementById('err_reqdesc').style.color = '#0979db';
		if (vchk == true) { vchk = true; }
	}
	
	if (pform.req_emid.value == "")
	{
		pform.req_emid.style.border = '2px solid #FF0000';
		pform.req_emid.focus();
		document.getElementById('err_reqemid').style.color = '#FF0000';
		vchk = false;
	}
	else if (!emailExp.test(pform.req_emid.value))
	{
		pform.req_emid.style.border = '2px solid #FF0000';
		pform.req_emid.focus();
		document.getElementById('err_reqemid').style.color = '#FF0000';
		vchk = false;
	}
	else
	{
		pform.req_emid.style.border = '1px solid #bcd3e8'
		document.getElementById('err_reqemid').style.color = '#0979db';
		if (vchk == true) { vchk = true; }
	}
	
	if (pform.req_pass.value == "")
	{
		pform.req_pass.style.border = '2px solid #FF0000';
		pform.req_pass.focus();
		document.getElementById('err_reqemid').style.color = '#FF0000';
		vchk = false;
	}
	else
	{
		pform.req_pass.style.border = '1px solid #bcd3e8'
		document.getElementById('err_reqemid').style.color = '#0979db';
		if (vchk == true) { vchk = true; }
	}
	
	if (vchk == true)
	{
		document.getElementById('actdiv').innerHTML = 'Posting Your Requirement!';
		//pform.target = 'postreqform';
		//pform.submit();
	}
}

function addBookmark(title,url) 
{
	if (window.sidebar) 
	{ 
		window.sidebar.addPanel(title, url,""); 
	} 
	else if( document.all ) 
	{
		window.external.AddFavorite( url, title);
	} 
	else if( window.opera && window.print ) 
	{
		return true;
	}
}

// -------------------------------------------------------------- End of Other Functions --------------------------------------------------------------------
