function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*
function onLoadCommonFunction(){
	MM_preloadImages('{$imageBasePath}/home-menu-r.jpg','{$imageBasePath}/service-r.jpg','{$imageBasePath}/port-r.jpg','{$imageBasePath}/register-r.jpg','{$imageBasePath}/pricing_r.jpg', '{$imageBasePath}/availability_box_bg.jpg','{$imageBasePath}/availability_box_cor_right.gif','{$imageBasePath}/availability_box_cor_left.gif', '{$imageBasePath}/button_face_bg.jpg');
	
	init();  //   For menu portion
}

function onLoadHomeFunction(){
	MM_preloadImages('{$imageBasePath}/home-menu-r.jpg','{$imageBasePath}/service-r.jpg','{$imageBasePath}/port-r.jpg','{$imageBasePath}/register-r.jpg','{$imageBasePath}/pricing_r.jpg', '{$imageBasePath}/availability_box_bg.jpg','{$imageBasePath}/availability_box_cor_right.gif','{$imageBasePath}/availability_box_cor_left.gif', '{$imageBasePath}/button_face_bg.jpg');
}*/


/* Popup function start here */
function popupImage(imageLink,where,hite,wide){
	if (window.event){ 
		window.event.returnValue = false;   
	}
	var width;
	var height;
	var imgWidth;
	var imgHeight;
	
	if (screen.width<wide){
		width=screen.width-20;
		imgWidth=width-10;
		var windowX = (screen.width-width)/2;
	}
	else{
		var windowX = (screen.width-wide)/2;
		width=wide;
	}

	if (screen.height<hite){
		height=screen.height-70;
		imgHeight=height-20;
		var windowY = (screen.height-height)/2-30;
	}
	else{
		var windowY = (screen.height-hite)/2-10;
		height=hite;
	}

	/*if (screen.width<wide || screen.height<hite){
		imageLink="../showimage.php?file=."+imageLink+"&width="+imgWidth+"&height="+imgHeight+"&full=1";
	}
	else{*/
		imageLink="zoom.php?image_path="+imageLink;
	//}

	//imageLink = where + imageLink ;
	//alert(imgHeight);
	
	var rand_no = Math.random();
	var i = Math.round(100*Math.random());
	if(screen.height<hite || screen.width<wide){
		var props=window.open(imageLink, i, 'scrollbars=1,toolabars=0,resizable=0,status=0,menubar=0,directories=0,location=0,height='+(hite+30)+', width='+(wide+30));
	}
	else{
		var props=window.open(imageLink, i, 'scrollbars=0,toolabars=0,resizable=0,status=0,menubar=0,directories=0,location=0,height='+(hite+30)+', width='+(wide+30));
	}
	props.moveTo(windowX,windowY);
}
/* Popup function end here */



function popupWindow(path, where, hite, wide){
	if (window.event){ 
		window.event.returnValue = false;   
	}
	var width;
	var height;
	var imgWidth;
	var imgHeight;
	
	if (screen.width<wide){
		width=screen.width-20;
		imgWidth=width-10;
		var windowX = (screen.width-width)/2;
	}
	else{
		var windowX = (screen.width-wide)/2;
		width=wide;
	}

	if (screen.height<hite){
		height=screen.height-70;
		imgHeight=height-20;
		var windowY = (screen.height-height)/2-30;
	}
	else{
		var windowY = (screen.height-hite)/2-10;
		height=hite;
	}

	var rand_no = Math.random();
	var i = Math.round(100*Math.random());
	if(screen.height<hite || screen.width<wide){
		var props=window.open(path, i, 'scrollbars=1,toolabars=0,resizable=0,status=0,menubar=0,directories=0,location=0,height='+(hite+30)+', width='+(wide+30));
	}
	else{
		var props=window.open(path, i, 'scrollbars=1,toolabars=0,resizable=0,status=0,menubar=0,directories=0,location=0,height='+(hite+30)+', width='+(wide+30));
	}
	props.moveTo(windowX,windowY);
}



/*
function dispJobsList(val){
	var imageID = 'disp_arrow'+val;
	var menuID = 'menu_list'+val;
	var imgpath = document.getElementById(imageID).src.split('/');
	var imgsrc = imgpath[imgpath.length-1];
		alert(menuID);

	if(imgsrc == 'calender.jpg'){
		ypSlideOutMenu.showMenu(menuID);
		MM_swapImage(imageID,'','../images/cal.gif',1);
	}
	else{
		ypSlideOutMenu.hideMenu(menuID);
		MM_swapImage(imageID,'','../images/calender.jpg',1);
	}
}
*/
if(window.ActiveXObject) {
	try {
		var oHTTP = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch(e) {
		var oHTTP = new ActiveXObject("Microsoft.XMLHTTP");
	}
} 
else {
	var oHTTP = new XMLHttpRequest();
}

	
/*******************************************************
For Job Details
*******************************************************/

function dispJobDetails(val){
	document.getElementById('jobDetailsPortion').innerHTML = '<img src="/images/loader.gif" alt="Please wait" style="margin: 50px 0 0 0;" />';
	document.getElementById('jobDetailsPortion').style.display = '';
	returnSingleJobDetails('/ajax_call.php?mode=singleJobDetails&ID='+val+'');
}

function returnSingleJobDetails(page) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if (getValue!="none") {
				document.getElementById('jobDetailsPortion').innerHTML = getValue;
				document.getElementById('jobDetailsPortion').style.display = '';
			}
		}
	}
	oHTTP.send(null);
}




function selectJobDisplay(val, val1){
	document.getElementById('jobDetails').innerHTML = '<img src="/images/loader.gif" alt="Please wait" style="margin: 50px 0 0 0;" />';
	returnJobDetails('/ajax_call.php?mode=jobDetails&catID='+val+'&pageID='+val1+'');
}

function returnJobDetails(page, divID) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if (getValue!="none") {
				document.getElementById('jobDetails').innerHTML = getValue;
			}
		}
	}
	oHTTP.send(null);
}

/*******************************************************
For User Login
*******************************************************/

function loginUser(){
	var userLoginName = document.forms['userLogin'].elements['user_login_name'].value;
	var userLoginPassword = document.forms['userLogin'].elements['user_login_password'].value;
	var autoLogin;
	if(document.forms['userLogin'].elements['auto_login'].checked==true){
		autoLogin = 1;
	}
	else{
		autoLogin = 0;
	}
	
	if(userLoginName==""){
		document.getElementById('overAll_err').innerHTML = '';
		document.getElementById('user_login_name_err').innerHTML = 'Please enter user name.';
		document.forms['userLogin'].elements['user_login_name'].focus();
		//return false;
	}
	if(userLoginPassword==""){
		document.getElementById('overAll_err').innerHTML = '';
		document.getElementById('user_login_password_err').innerHTML = 'Please enter your password.';
		if(userLoginName!=""){
			document.forms['userLogin'].elements['user_login_password'].focus();
		}
		else{
			document.forms['userLogin'].elements['user_login_name'].focus();
		}
		//return false;
	}
	if(userLoginPassword!="" && userLoginName!=""){
		document.getElementById('user_login_name_err').innerHTML = '';
		document.getElementById('user_login_password_err').innerHTML = '';
		document.getElementById('overAll_err').innerHTML = '';
	
		userLoginPage('/ajax_call.php?mode=user_login&user_login_name='+userLoginName+'&user_login_password='+userLoginPassword+'&auto_login='+autoLogin+'');
		//return false;
	}
	return false;
}

function userLoginPage(page) {
	oHTTP.open("POST", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			
			if(getValue=="done"){
				location.href='check_payment.php';
			}
			else{
				if(getValue=="Err"){
					document.getElementById('overAll_err').innerHTML = 'Sorry! You have entered wrong user name or password.';
				}
				else{
					var temp = new Array();
					temp = getValue.split('||||');
					document.getElementById('user_login_name_err').innerHTML = temp[0];
					document.getElementById('user_login_password_err').innerHTML = temp[1];
					document.getElementById('overAll_err').innerHTML = temp[2];
				}
			}
		}
	}
	oHTTP.send(null);
}


function loginUserPage(){
	var userLoginName = document.forms['userLoginPage'].elements['user_login_name_page'].value;
	var userLoginPassword = document.forms['userLoginPage'].elements['user_login_password_page'].value;
	var autoLogin;
	if(document.forms['userLoginPage'].elements['auto_login_page'].checked==true){
		autoLogin = 1;
	}
	else{
		autoLogin = 0;
	}
	
	
	document.getElementById('user_login_name_page_err').innerHTML = '';
	document.getElementById('user_login_password_page_err').innerHTML = '';
	document.getElementById('overAll_err_page').innerHTML = '';

	userLoginPage_page('/ajax_call.php?mode=user_login&user_login_name='+userLoginName+'&user_login_password='+userLoginPassword+'&auto_login='+autoLogin+'');
}

function userLoginPage_page(page) {
	oHTTP.open("POST", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if (getValue!="Err") {
				var temp = new Array();
				temp = getValue.split('||||');
				document.getElementById('user_login_name_page_err').innerHTML = temp[0];
				document.getElementById('user_login_password_page_err').innerHTML = temp[1];
				document.getElementById('overAll_err_page').innerHTML = temp[2];
			}
			else if(getValue!="Err"){
				document.getElementById('overAll_err_page').innerHTML = 'Sorry! You have entered wrong user name or password.';
			}
			else{
				location.href='check_payment.php';
			}
		}
	}
	oHTTP.send(null);
}



function getJobPrice(jobID, frmName, fieldName, messageArea){
	returnJobPrice('/ajax_call.php?mode=get_job_price&jobID='+jobID+'', frmName, fieldName, messageArea)
}


function returnJobPrice(page, frmName, fieldName, messageArea) {
	oHTTP.open("POST", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if (getValue!="Err") {
				var jobPrice = getValue.split(" ");
				document.forms[frmName].elements[fieldName].value=jobPrice[0];
				document.forms[frmName].elements['currency'].value=jobPrice[1];
				document.getElementById(messageArea).innerHTML = getValue;
				document.getElementById(messageArea).style.display = '';
			}
			else{
				document.forms[frmName].elements[fieldName].value='';
				document.forms[frmName].elements['currency'].value='';
				document.getElementById(messageArea).innerHTML = '';
			}
		}
	}
	oHTTP.send(null);
}


/*******************************************************
For Check User Details
*******************************************************/
function checkUserName(){
	if(document.forms['userRegistration'].elements['user_name'].value==""){
		document.getElementById('textContentHTML').innerHTML = 'Please enter user name.';
		document.getElementById('theLayer').style.visibility = 'visible';	
		return false;
	}
	var userLoginName = document.forms['userRegistration'].elements['user_name'].value;
	var firstName = document.forms['userRegistration'].elements['first_name'].value;
	var lastName = document.forms['userRegistration'].elements['family_name'].value;
	
	checkUser('/ajax_call.php?mode=check_username&user_name='+userLoginName+'&first_name='+firstName+'&family_name='+lastName+'');
}

function checkUser(page) {
	oHTTP.open("POST", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			//alert(getValue);
			document.getElementById('textContentHTML').innerHTML = getValue;
			document.getElementById('theLayer').style.visibility = 'visible';
		}
	}
	oHTTP.send(null);
}


function changeUsernameValue(val){
	document.forms['userRegistration'].elements['user_name'].value = val;
	hideMe(); 
	return false;
}


/*******************************************************
Login Message
*******************************************************/
function loginMessage(val, popupHeader, val1){
	var screenWidth = parseInt(screen.width)-200;
	var screenHeight = parseInt(document.body.scrollHeight)-40;
	var leftPos = (screenWidth/2)+'px';
	var topPos = (screenHeight/2)+'px';
	
	//alert(document.getElementById(val1).style.top);
	
	document.getElementById('theLayer').style.top = topPos;
	document.getElementById('theLayer').style.left = leftPos;
	document.getElementById('popup_header').innerHTML = popupHeader;
	
	document.getElementById('theLayer').style.visibility = 'visible';
	var printTEXT;
	printTEXT = '<span class="err">'+val+'</span><br><span class="smalltext"><br>Registered user <a href="#" onclick="javascript: loginFocus(); return false;" class="view_link"><b>click here</b></a> to login.<br><br>If you are not registered member <a href="/user_registration.php" onclick="document.getElementById(\'theLayer\').style.visibility=hidden;" class="view_link"><b>click here</b></a> to register.<br><br>';
	document.getElementById('textContentHTML').innerHTML = printTEXT;
}


function setJobPath(val1, val2){
	setJobID('/ajax_call.php?mode=setJobPath&job_id='+val1+'&from='+val2+'');
}

function setJobID(page) {
	oHTTP.open("POST", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
		}
	}
	oHTTP.send(null);
}

function loginFocus(){
	document.getElementById('overAll_err').innerHTML = 'Please login here.';
	document.forms['userLogin'].elements['user_login_name'].style.background = '#FEC208';
	document.forms['userLogin'].elements['user_login_name'].focus();
	document.getElementById('theLayer').style.visibility='hidden';
}




/*******************************************************
category details 
*******************************************************/
function categoryDetails(val){
	document.getElementById('categoryDetails').innerHTML = '<img src="/images/loader.gif" alt="Please wait" style="margin: 50px 0 0 0;" />';
	document.getElementById('categoryDetails').style.display = '';
	returnCategoryDetails('/ajax_call.php?mode=categoryDetails&ID='+val+'');
}

function returnCategoryDetails(page) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if (getValue!="none") {
				document.getElementById('categoryDetails').innerHTML = getValue;
				document.getElementById('categoryDetails').style.display = '';
			}
		}
	}
	oHTTP.send(null);
}

function hideCategoryDetails(){
	document.getElementById('categoryDetails').style.display = 'none';	
}


/*******************************************
For job Details postion
***********************************************/

var remember = false; //Remember menu states, and restore them on next visit.
var contractall_default= true; //Should all submenus be contracted by default? (true or false)

var menu, titles, submenus, arrows, bypixels;
var heights = new Array();

var n = navigator.userAgent;
if(/Opera/.test(n)) bypixels = 2;
else if(/Firefox/.test(n)) bypixels = 3;
else if(/MSIE/.test(n)) bypixels = 2;

/////DD added expandall() and contractall() functions/////

function slash_expandall(){
if (typeof menu!="undefined"){
	for(i=0; i<Math.max(titles.length, submenus.length); i++){
		titles[i].className="title";
		arrows[i].src = "../images/arrow_on_white_up.jpg";
		submenus[i].style.display="";
		submenus[i].style.height = heights[i]+"px";
	}
}
}

function slash_contractall(){
if (typeof menu!="undefined"){
	for(i=0; i<Math.max(titles.length, submenus.length); i++){
		titles[i].className="titlehidden";
		arrows[i].src = "../images/arrow_on_white_dn.jpg";
		submenus[i].style.display="none";
		submenus[i].style.height = 0;
	}
}
}


/////End DD added functions///////////////////////////////


function init(){
    menu = getElementsByClassName("sdmenu", "div", document)[0];
    titles = getElementsByClassName("title", "span", menu);
    submenus = getElementsByClassName("submenu", "div", menu);
    arrows = getElementsByClassName("arrow", "img", menu);
    for(i=0; i<Math.max(titles.length, submenus.length); i++) {
        //titles[i].onclick = gomenu;
       	//arrows[i].onclick = gomenu;
        heights[i] = submenus[i].offsetHeight;
        submenus[i].style.height = submenus[i].offsetHeight+"px";
    }
    if(remember)
				restore()
		else if (contractall_default) //DD added code
				slash_contractall() //DD added code
}


function restore() {
    if(getcookie("menu") != null) {
        var hidden = getcookie("menu").split(",");
        for(var i in hidden) {
            titles[hidden[i]].className = "titlehidden";
            submenus[hidden[i]].style.height = "0px";
            submenus[hidden[i]].style.display = "none";
            arrows[hidden[i]].src = "../images/arrow_on_white_dn.jpg";
        }
    }
}

//alert(window.event);

function gomenu(e) {
    if (!e)
        var e = window.event;
    var ce = (e.target) ? e.target : e.srcElement;
    var sm;
    for(var i in titles) {
        if(titles[i] == ce || arrows[i] == ce)
            sm = i;
    }
    if(parseInt(submenus[sm].style.height) > parseInt(heights[sm])-2) {
		hideCategoryDetails();
        hidemenu(sm);
    } else if(parseInt(submenus[sm].style.height) < 2) {
        titles[sm].className = "title";
		showmenu(sm);
		for(var i in titles) {
			if(i!=sm){
				hidemenu(i);	
			}
		}
    }
}

function gotoManuList(sm, catID, totalCat){
	if(parseInt(submenus[sm].style.height) > parseInt(heights[sm])-2) {
		hideCategoryDetails();
        hidemenu(sm);
    } 
	else if(parseInt(submenus[sm].style.height) < 2) {
        titles[sm].className = "title";
		categoryDetails(catID);
		showmenu(sm);
		for(i=0; i<=totalCat; i++) {
			if((submenus[i].style.display == "" || submenus[i].style.display == "block") && i!=sm) {
				hideCategoryDetails();
				hidemenu(i);
			} 
		}
    }	
}

function hidemenu(sm) {
    var nr = submenus[sm].getElementsByTagName("a").length*bypixels;
    submenus[sm].style.height = (parseInt(submenus[sm].style.height)-nr)+"px";
    var to = setTimeout("hidemenu("+sm+")", 30);
    if(parseInt(submenus[sm].style.height) <= nr) {
        clearTimeout(to);
        submenus[sm].style.display = "none";
        submenus[sm].style.height = "0px";
        arrows[sm].src = "../images/arrow_on_white_dn.jpg";
        titles[sm].className = "titlehidden";
    }
}

function showmenu(sm) {
	var nr = submenus[sm].getElementsByTagName("a").length*bypixels;
    submenus[sm].style.display = "";
    submenus[sm].style.height = (parseInt(submenus[sm].style.height)+nr)+"px";
    var to = setTimeout("showmenu("+sm+")", 30);
    if(parseInt(submenus[sm].style.height) > (parseInt(heights[sm])-nr)) {
        clearTimeout(to);
        submenus[sm].style.height = heights[sm]+"px";
        arrows[sm].src = "../images/arrow_on_white_up.jpg";
    }
        
        
}

function store() {
    var hidden = new Array();
    for(var i in titles) {
        if(titles[i].className == "titlehidden")
            hidden.push(i);
    }
    putcookie("menu", hidden.join(","), 30);
}

function getElementsByClassName(strClassName, strTagName, oElm){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

function putcookie(c_name,value,expiredays) {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate);
}

function getcookie(c_name) {
    if(document.cookie.length > 0) {
        var c_start = document.cookie.indexOf(c_name + "=");
        if(c_start != -1) {
            c_start = c_start + c_name.length + 1;
            var c_end = document.cookie.indexOf(";",c_start);
            if(c_end == -1)
                c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return null;
}

//window.onload = init;
if(remember) window.onunload = store;