//******************************************************//

//ajax.js :: Begin

//******************************************************//


//declare a global  XMLHTTP Request object
var XmlHttpObj;
//create an instance of XMLHTTPRequest Object, varies with browser type, try
//for IE first then Mozilla
function CreateXmlHttpObj() {
	// try creating for IE (note: we don't know the user's browser type here,just attempting IE first.)
	try {
		XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (oc) {
			XmlHttpObj = null;
		}
	}
	// if unable to create using IE specific code then try creating for Mozilla
	// (FireFox)
	if (!XmlHttpObj && typeof XMLHttpRequest != "undefined") {
		XmlHttpObj = new XMLHttpRequest();
	}
}

function callAjax(requestUrl, ajaxHandler) {
	CreateXmlHttpObj();
	// verify XmlHttpObj variable was successfully initialized
	if (XmlHttpObj) {
		// assign the StateChangeHandler function ( defined below in this file)
		// to be called when the state of the XmlHttpObj changes
		// receiving data back from the server is one such change
		XmlHttpObj.onreadystatechange = ajaxHandler;
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl, true);
		// send request to server, null arg when using "GET"
		XmlHttpObj.send(null);
	}
}

function GetInnerText(node) {
	return (node.textContent || node.innerText || node.text);
}

//******************************************************//

//ajax.js :: End

//******************************************************//


//******************************************************//

//search_ajax.js :: Begin

//******************************************************//
var str;
var magazine_name = '';
var magazineIssueIdArray = new Array();

function showHint(str, flag,publisherId,archive) {
    if (str.length == 0) {
        document.getElementById("suggestions").innerHTML = "";
        document.getElementById("suggestions").style.display = 'none';
        return;
    }
    var requestUrl;
    requestUrl = "search.php" + "?suggestion=" + encodeURIComponent(str)+'&publisherID='+encodeURIComponent(publisherId)+ "&flag=" + encodeURIComponent(flag) + "&archive=" + encodeURIComponent(archive);
 //alert(requestUrl );
    callAjax(requestUrl, StateChangeHandlerforSuggestion);
}

function StateChangeHandlerforSuggestion() {
    if (XmlHttpObj.readyState == 4) {
        if (XmlHttpObj.status == 200) {
            populateSuggestion(XmlHttpObj.responseXML.documentElement);
        } else {
            logError('search_ajax.js',"StateChangeHandlerforSuggestion: problem retrieving data from the server, status code: "+ XmlHttpObj.status);
        }
    }
}

function populateSuggestion(Node) {
    var id = Node.getElementsByTagName('id');
    var shortname = Node.getElementsByTagName('shortname');
    var subdomain = Node.getElementsByTagName('subdomain');
    var issuenumber = Node.getElementsByTagName('issuenumber');
    var magazine = Node.getElementsByTagName('name');
    //alert(suggestions);

    var suggestions = '';
    suggestions = '<ul id="ulist">';
    var val;
    var currentFocusIndex = 0;
    for ( var count = 0; count < shortname.length; count++) {
        val = "list" + count;
        currentFocusIndex = count + 1;
        if (GetInnerText(shortname[count]) == 'no suggestion') {
            suggestions = suggestions+ '<li  id=\"'+ val+ '\" name="'+ GetInnerText(shortname[count])+ '" TABINDEX=\"'+ currentFocusIndex+ '\" onblur= this.style.background="#FFF"; onfocus= this.style.background="#FF9";populate(document.getElementById(\"'+ val + '\").getAttribute("name"));>'+ GetInnerText(shortname[count]) + '</li>';
        } else {
            suggestions = suggestions+ '<li  id=\"'+ val+ '\"name="'+ GetInnerText(shortname[count])+ '" TABINDEX=\"'+ currentFocusIndex+ '\" onblur= this.style.background="#FFF"; onfocus= this.style.background="#FF9";populate(document.getElementById(\"'+ val+ '\").getAttribute("name"));><a href=javascript:populateTextBox(document.getElementById(\"'+ val + '\").getAttribute("name"),"'+GetInnerText(subdomain[count])+'","'+GetInnerText(id[count])+'","'+GetInnerText(issuenumber[count])+'","'+GetInnerText(magazine[count])+'");>'+ GetInnerText(shortname[count]) + '</a></li>';
            magazineIssueIdArray[GetInnerText(shortname[count])] = GetInnerText(issuenumber[count]);        
        }
    }
    suggestions = suggestions + '</ul>';
//alert(suggestions);
    if (shortname.length > 0) {
        document.getElementById("suggestions").style.display = '';
        document.getElementById("suggestions").innerHTML = suggestions;
        var el = document.getElementById("ulist");
        if (navigator.appName == "Netscape") {
            document.getElementById('ulist').onkeypress = HandleKeyPress;
        } else {
            el.attachEvent('onkeypress', HandleKeyPress);
        }
        var down = 0;
        var up = 0;
        function capturekey(e) {
            var key = (typeof event != 'undefined') ? window.event.keyCode : e.keyCode;
            if (key == 40) {
                for ( var count = 0; count < shortname.length; count++) {
                    if (count == down) {
                        document.getElementById("ulist").childNodes[count].focus();
                        down++;
                        break;
                    }
                }
                up = down - 1;
            }
            if (key == 38) {
                --up;
                for ( count = 0; count < shortname.length; count++) {
                    if (count == up) {
                        document.getElementById("ulist").childNodes[count].focus();
                        break;
                    }
                }
                down = up + 1;
            }
            if (key == 13) {
                document.getElementById("search").focus();
                document.getElementById("search").value = magazine_name;
                document.getElementById("suggestions").style.display = 'none';
                for ( var magazineName in magazineIssueIdArray) {
                    if (magazineName == document.getElementById("search").value) {
                        document.getElementById("issueId").value = magazineIssueIdArray[magazineName];
                    }
                } 
                return;
            }
        }
        if (navigator.appName != "Mozilla") {
            document.onkeyup = capturekey;
        } else {
            document.addEventListener("keyup", capturekey, true);
        }
    }
}

function populateTextBox(value, subdomain, mag_lang_id, issueNumber,magName) {
    document.getElementById("search").focus();
    document.getElementById("search").value = value;
    document.getElementById("suggestions").style.display = 'none';
    for ( var magazineName in magazineIssueIdArray) {
        if (magazineName == document.getElementById("search").value) {
            document.getElementById("issueId").value = magazineIssueIdArray[magazineName];
        }
    }
    if(document.getElementById("issueId").value!=0){
        window.open('http://'+subdomain+'.menamag.me/magazines/'+mag_lang_id+'/'+issueNumber+'/'+magName+'.php');
        document.getElementById('issueId').value=0;
    }
    return;
}

function populate(value) {
    magazine_name = value;
}

function HandleKeyPress(e) {
    e = e || window.event;
    switch (e.keyCode) {
        case e.DOM_VK_LEFT:
        case e.DOM_VK_RIGHT:
        case e.DOM_VK_UP:
        case e.DOM_VK_DOWN:
            if (e.preventDefault)
                e.preventDefault();
            else
                e.returnValue = false;
    }
}

//******************************************************//

//search_ajax.js :: End

//******************************************************//

//******************************************************//

//news_ajax.js :: Begin

//******************************************************//


function prevNews(newsId) {
	var requestUrl;
	newsId = newsId - 1;
	requestUrl = "news_form.php" + "?ID=" + encodeURIComponent('' + newsId);
	callAjax(requestUrl, StateChangeHandlerforPrevNews);
}

function StateChangeHandlerforPrevNews() {
	if (XmlHttpObj.readyState == 4) {
		// To make sure valid response is received from the server, 200 means
		// response received is OK
		if (XmlHttpObj.status == 200) {
			document.getElementById("news").innerHTML = XmlHttpObj.responseText;
		} else {
			logError('news_ajax.js',"StateChangeHandlerforPrevNews: problem retrieving data from the server, status code: "+ XmlHttpObj.status);
		}
	}
}

function nextNews(newsId) {
	var requestUrl;
	newsId = (newsId*1) + 1;
	requestUrl = "news_form.php" + "?ID=" + encodeURIComponent('' + newsId);
    callAjax(requestUrl, StateChangeHandlerforNextNews);
}

function StateChangeHandlerforNextNews() {
	if (XmlHttpObj.readyState == 4) {
    	// To make sure valid response is received from the server, 200 means
		// response received is OK
		if (XmlHttpObj.status == 200) {
			document.getElementById("news").innerHTML = XmlHttpObj.responseText;
		} else {
			logError('news_ajax.js',"StateChangeHandlerforNextNews: problem retrieving data from the server, status code: "+ XmlHttpObj.status);
		}
	}
}


//******************************************************//

//news_ajax.js :: End

//******************************************************//

//******************************************************//

//info_ajax.js :: Begin

//******************************************************//

function displayInfo(issueId) {
	var requestUrl;
	requestUrl = "info.php" + "?issueId=" + encodeURIComponent('' + issueId);
    document.getElementById("layer1").innerHTML = "";
	callAjax(requestUrl, StateChangeHandlerforInfo);
}

function StateChangeHandlerforInfo() {
	if (XmlHttpObj.readyState == 4) {
		// To make sure valid response is received from the server, 200 means
		// response received is OK
		if (XmlHttpObj.status == 200) {
			populateInfo(XmlHttpObj.responseText);
		} else {
			logError('info_ajax.js',"StateChangeHandlerforInfo: problem retrieving data from the server, status code: "+ XmlHttpObj.status);
		}
	}
}

function populateInfo(htmlText) {
	document.getElementById("layer1").innerHTML = htmlText;
}



//******************************************************//

//info_ajax.js :: End

//******************************************************//


//******************************************************//

//display_ajax.js :: Begin

//******************************************************//



function displayMagazines(categoryId,countryCode,languageId,flag,archFlag) {



	var requestUrl;



    requestUrl = "display_form.php" + "?categoryId=" + encodeURIComponent(categoryId)+"&countryCode=" + encodeURIComponent(countryCode)+"&languageId=" + encodeURIComponent(languageId)+ "&flag=" + encodeURIComponent(flag)+ "&archFlag=" + encodeURIComponent(archFlag);



    callAjax(requestUrl,StateChangeHandler);



}







function StateChangeHandler() {



	if(XmlHttpObj.readyState == 4) {



		// To make sure valid response is received from the server, 200 means response received is OK



		if(XmlHttpObj.status == 200) {		



			document.getElementById("content_main").innerHTML = XmlHttpObj.responseText;

            $(document).ready(function(){



                $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)



                $("ul.topnav li span").hover(function() { //When trigger is clicked...



                    //Following events are applied to the subnav itself (moving subnav up and down)

                    $(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click



                    $(this).parent().hover(function() {

                        }, function(){

                            $(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up

                        });



                //Following events are applied to the trigger (Hover events for the trigger)

                }).hover(function() {

                    $(this).addClass("subhover"); //On hover over, add class "subhover"

                }, function(){	//On Hover Out

                    $(this).removeClass("subhover"); //On hover out, remove class "subhover"

                });



            });





		}else {



			logError('display_ajax.js',"StateChangeHandler: problem retrieving data from the server, status code: "+ XmlHttpObj.status);

		}



	}



}



//******************************************************//

//display_ajax.js :: End

//******************************************************//



//******************************************************//

//paging_ajax.js :: Begin

//******************************************************//

function displayMagazinesByPage(categoryId, countryCode, languageId, limit,flag,archFlag) {







	var requestUrl;







	requestUrl = "display_form.php" + "?categoryId="







			+ encodeURIComponent(categoryId) + "&countryCode="







			+ encodeURIComponent(countryCode) + "&languageId="







			+ encodeURIComponent(languageId) + "&limit="







			+ encodeURIComponent(limit)+ "&flag="+encodeURIComponent(flag)+ "&archFlag=" + encodeURIComponent(archFlag);







	callAjax(requestUrl, StateChangeHandlerForPaging);







}















function StateChangeHandlerForPaging() {







	if (XmlHttpObj.readyState == 4) {







		// To make sure valid response is received from the server, 200 means







		// response received is OK







		if (XmlHttpObj.status == 200) {







			document.getElementById("content_main").innerHTML = XmlHttpObj.responseText;







		} else {







			logError('paging_ajax.js',"StateChangeHandlerForPaging: problem retrieving data from the server, status code: "+ XmlHttpObj.status);







		}







	}







}



//******************************************************//

//paging_ajax.js :: End

//******************************************************//





//******************************************************//

//filter_ajax.js :: Begin

//******************************************************//



//Developed by Naseena







// called from onChange or onClick event of the Value dropdown list



function categoryListOnChange(flag,archFlag) {







	var listName;



	listName = document.getElementById("categoryList");







	// get selected Value from dropdown list



	var selectedValue = listName.options[listName.selectedIndex].value;



	categoryFilterValue = selectedValue;



	// url of page that will send xml data back to client browser



	var requestUrl;



	requestUrl = "filter.php" + "?listType=category&categoryFilter="



			+ encodeURIComponent(selectedValue) + "&flag="



			+ encodeURIComponent(flag)+ "&archFlag=" + encodeURIComponent(archFlag);



      //alert(requestUrl);



	callAjax(requestUrl, StateChangeHandlerforCategory);







}



function countryListOnChange(flag,archFlag) {



	var listName;







	 listName = document.getElementById("countryList");



	var categoryFilter = document.getElementById("categoryList");



	var categoryFilterValue = categoryFilter.options[categoryFilter.selectedIndex].value;



	// get selected Value from dropdown list



	var selectedValue = listName.options[listName.selectedIndex].value;







	// url of page that will send xml data back to client browser



	var requestUrl;



	requestUrl = "filter.php" + "?listType=country&categoryFilter="



			+ encodeURIComponent(categoryFilterValue) + "&countryFilter="



			+ encodeURIComponent(selectedValue) + "&flag="



			+ encodeURIComponent(flag)+ "&archFlag=" + encodeURIComponent(archFlag);







	callAjax(requestUrl, StateChangeHandlerforCountry);



}







// this function called when state of  XmlHttpObj changes



// we're interested in the state that indicates data has been



// received from the server



function StateChangeHandlerforCategory() {



	// state ==4 indicates receiving response data from server is completed



	if (XmlHttpObj.readyState == 4) {



		// To make sure valid response is received from the server, 200 means response received is OK



		if (XmlHttpObj.status == 200) {



			PopulateCountryAndLanguageList(XmlHttpObj.responseXML.documentElement);



		} else {



			logError('filter_ajax.js',"StateChangeHandlerforCategory: problem retrieving data from the server, status code: "+ XmlHttpObj.status);

		}



	}



}



function StateChangeHandlerforCountry() {



	// state ==4 indicates receiving response data from server is completed



	if (XmlHttpObj.readyState == 4) {



		// To make sure valid response is received from the server, 200 means response received is OK



		if (XmlHttpObj.status == 200) {



			PopulateLanguageList(XmlHttpObj.responseXML.documentElement);



		} else {



			logError('filter_ajax.js',"StateChangeHandlerforCountry: problem retrieving data from the server, status code: "+ XmlHttpObj.status);



		}



	}



}







// populate the contents of thedropdown list



function PopulateCountryAndLanguageList(Node) {



	var countryList = document.getElementById("countryList");



	var languageList = document.getElementById("languageList");



	// clear the country list 



	for ( var count = countryList.options.length - 1; count > 0; count--) {



		countryList.options[count] = null;



	}



	// clear the language list 



	for ( var count = languageList.options.length - 1; count > 0; count--) {



		languageList.options[count] = null;



	}



	var countryNodes = Node.getElementsByTagName('country');



	var idValueForCountry;



	var textValueForCountry;



	var optionItemForCountry;



	// populate the dropdown list with data from the xml doc



	for ( var count = 0; count < countryNodes.length; count++) {



		textValueForCountry = GetInnerText(countryNodes[count]);



		idValueForCountry = countryNodes[count].getAttribute("id");



		optionItemForCountry = new Option(textValueForCountry,



				idValueForCountry, false, false);



		countryList.options[countryList.length] = optionItemForCountry;



	}



	var languageNodes = Node.getElementsByTagName('language');



	var idValueForLanguage;



	var textValueForLanguage;



	var optionItemForLanguage;



	// populate the dropdown list with data from the xml doc



	for ( var count = 0; count < languageNodes.length; count++) {



		textValueForLanguage = GetInnerText(languageNodes[count]);



		idValueForLanguage = languageNodes[count].getAttribute("id");



		optionItemForLanguage = new Option(textValueForLanguage,



				idValueForLanguage, false, false);



		languageList.options[languageList.length] = optionItemForLanguage;



	}



}



function PopulateLanguageList(Node) {







	var languageList = document.getElementById("languageList");



	for ( var count = languageList.options.length - 1; count > 0; count--) {



		languageList.options[count] = null;



	}



	var languageNodes = Node.getElementsByTagName('language');



	var idValueForLanguage;



	var textValueForLanguage;



	var optionItemForLanguage;



	// populate the dropdown list with data from the xml doc



	for ( var count = 0; count < languageNodes.length; count++) {



		textValueForLanguage = GetInnerText(languageNodes[count]);



		idValueForLanguage = languageNodes[count].getAttribute("id");



		optionItemForLanguage = new Option(textValueForLanguage,



				idValueForLanguage, false, false);



		languageList.options[languageList.length] = optionItemForLanguage;



	}



}





//******************************************************//

//filter_ajax.js :: End

//******************************************************//





//******************************************************//

//publisher_box.js :: Begin

//******************************************************//





var publisherIndex = 0;



function initImage(imageId) {



	  image = document.getElementById(imageId);



	  setOpacity(image, 0);



	  image.style.visibility = 'visible';



	  fadeIn(imageId,0);



	}



	function setOpacity(obj, opacity) {



	  opacity = (opacity == 100)?99.999:opacity;



	  



	  // IE/Win



	  obj.style.filter = "alpha(opacity:"+opacity+")";



	  



	  // Safari<1.2, Konqueror



	  obj.style.KHTMLOpacity = opacity/100;



	  



	  // Older Mozilla and Firefox



	  obj.style.MozOpacity = opacity/100;



	  



	  // Safari 1.2, newer Firefox and Mozilla, CSS3



	  obj.style.opacity = opacity/100;



	}



	function fadeIn(objId,opacity) {



	  if (document.getElementById) {



	    obj = document.getElementById(objId);



	    if (opacity <= 100) {



	      setOpacity(obj, opacity);



	      opacity += 8;



	      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 150);



	    }



	  }



	}











function changePublisherDiv() {



	var main_div0 = document.getElementById("main_div0");



	var main_div1 = document.getElementById("main_div1");



	var main_div2 = document.getElementById("main_div2");



	



	initImage("main_div0");



	initImage("main_div1");



	initImage("main_div2");



	main_div0.innerHTML = main_div1.innerHTML;



	main_div1.innerHTML = main_div2.innerHTML;



	



	publisherIndex = (publisherIndex + 1) % 30;



   //   if(publisherIndex ==8){

	////	publisherIndex = 1;

    //  }

   //   if(publisherIndex > 8){

	//	publisherIndex = 0;

     // }



	var pdiv = document.getElementById("pdiv" + publisherIndex);



	main_div2.innerHTML = pdiv.innerHTML;







	setTimeout('changePublisherDiv()', 10000);



}







setTimeout('changePublisherDiv()', 10000);







//******************************************************//

//publisher_boxjs :: End

//******************************************************//







//******************************************************//

//dialog_box.js :: Begin

//******************************************************//

// global variables //

var TIMER = 5;

var SPEED = 10;

var WRAPPER = 'content';



// calculate the current window width //
function pageWidth() {

  return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;

}



// calculate the current window height //

function pageHeight() {

  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;

}



// calculate the current window vertical offset //

function topPosition() {

  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;

}



// calculate the position starting at the left of the window //

function leftPosition() {

  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;

}



// build/show the dialog box, populate the data and call the fadeDialog function //

function showDialog(title,message,type,autohide) {

  if(!type) {

    type = 'error';

  }

  var dialog;

  var dialogheader;

  var dialogclose;

  var dialogtitle;

  var dialogcontent;

  var dialogmask;

  if(!document.getElementById('dialog')) {

    dialog = document.createElement('div');

    dialog.id = 'dialog';

    dialogheader = document.createElement('div');

    dialogheader.id = 'dialog-header';

    dialogtitle = document.createElement('div');

    dialogtitle.id = 'dialog-title';

    dialogclose = document.createElement('div');

    dialogclose.id = 'dialog-close'

    dialogcontent = document.createElement('div');

    dialogcontent.id = 'dialog-content';

    dialogmask = document.createElement('div');

    dialogmask.id = 'dialog-mask';

    document.body.appendChild(dialogmask);

    document.body.appendChild(dialog);

    dialog.appendChild(dialogheader);

    dialogheader.appendChild(dialogtitle);

    dialogheader.appendChild(dialogclose);

    dialog.appendChild(dialogcontent);;

    dialogclose.setAttribute('onclick','hideDialog()');

    dialogclose.onclick = hideDialog;

  } else {

    dialog = document.getElementById('dialog');

    dialogheader = document.getElementById('dialog-header');

    dialogtitle = document.getElementById('dialog-title');

    dialogclose = document.getElementById('dialog-close');

    dialogcontent = document.getElementById('dialog-content');

    dialogmask = document.getElementById('dialog-mask');

    dialogmask.style.visibility = "visible";

    dialog.style.visibility = "visible";

  }

  dialog.style.opacity = .00;

  dialog.style.filter = 'alpha(opacity=0)';

  dialog.alpha = 0;

  var width = pageWidth();

  var height = pageHeight();

  var left = leftPosition();

  var top = topPosition();

  var dialogwidth = dialog.offsetWidth;

  var dialogheight = dialog.offsetHeight;

  var topposition = top + (height / 3) - (dialogheight / 2);

  var leftposition = left + (width / 2) - (dialogwidth / 2);

  dialog.style.top = topposition + "px";

  dialog.style.left = leftposition + "px";

  dialogheader.className = type + "header";

  dialogtitle.innerHTML = title;

  dialogcontent.className = type;

  dialogcontent.innerHTML = message;

  var content = document.getElementById(WRAPPER);

  dialogmask.style.height = content.offsetHeight + 'px';

  dialog.timer = setInterval("fadeDialog(1)", TIMER);

  if(autohide) {

    dialogclose.style.visibility = "hidden";

    window.setTimeout("hideDialog()", (autohide * 1000));

  } else {

    dialogclose.style.visibility = "visible";

  }

}



// hide the dialog box //

function hideDialog() {

  var dialog = document.getElementById('dialog');

  clearInterval(dialog.timer);

  dialog.timer = setInterval("fadeDialog(0)", TIMER);

}



// fade-in the dialog box //

function fadeDialog(flag) {

  if(flag == null) {

    flag = 1;

  }

  var dialog = document.getElementById('dialog');

  var value;

  if(flag == 1) {

    value = dialog.alpha + SPEED;

  } else {

    value = dialog.alpha - SPEED;

  }

  dialog.alpha = value;

  dialog.style.opacity = (value / 100);

  dialog.style.filter = 'alpha(opacity=' + value + ')';

  if(value >= 99) {

    clearInterval(dialog.timer);

    dialog.timer = null;

  } else if(value <= 1) {

    dialog.style.visibility = "hidden";

    document.getElementById('dialog-mask').style.visibility = "hidden";

    clearInterval(dialog.timer);

  }

}



//******************************************************//

//dialog_box.js :: End

//******************************************************//

//******************************************************//

//utility.js :: Begin

//******************************************************//


var cX = 0; var cY = 0; var rX = 0; var rY = 0;

function UpdateCursorPosition(e){ 
    cX = e.pageX; cY = e.pageY;
}

function UpdateCursorPositionDocAll(e){ 
    cX = event.clientX; cY = event.clientY;
}

if(document.all) { 
    document.onmousemove = UpdateCursorPositionDocAll;
}else { 
    document.onmousemove = UpdateCursorPosition;
}

function AssignPosition(d,divName) {
    if(self.pageYOffset) {
        rX = self.pageXOffset;
        rY = self.pageYOffset;
    }else if(document.documentElement && document.documentElement.scrollTop) {
        rX = document.documentElement.scrollLeft;
        rY = document.documentElement.scrollTop;
    }else if(document.body) {
        rX = document.body.scrollLeft;
        rY = document.body.scrollTop;
    }
    if(document.all) {
        cX += rX;
        cY += rY;
    }
    if(divName == 'layer1') {
         d.style.left = (cX+10-170) + "px";
         d.style.top = (cY+10) + "px";
    }else{
         d.style.left = (cX+3) + "px";
         d.style.top = (cY+3) + "px";
    }

   
}

function HideContent(d) {
    if(d.length < 1) {
        return;
    }
    document.getElementById(d).style.display = "none";
}

function ShowContent(d) {
    if(d.length < 1) {
        return;
    }
    var dd = document.getElementById(d);
    AssignPosition(dd,d);
    dd.style.display = "block";
}

function showPopup(url){
    newwindow=window.open(url);
    if (window.focus) {
        newwindow.focus();
    }
}

function autoHide() {
    setTimeout('HideContent(\'layer1\')', 10000);
}

function escapeKey(e) {
    var key = (typeof event != 'undefined') ? window.event.keyCode
    : e.keyCode;
    if(key==27) {
        HideContent('layer1');
    }
}

function clearSearch(textBoxName) {
    var input = document.getElementById(textBoxName);
    input.value = "";
}
//To log the error messages to the database
function logError(fileName,message) {
	var requestUrl;
	requestUrl = "errorLog_action.php" + "?f=" + encodeURIComponent('' + fileName)+ "&e=" + encodeURIComponent('' + message);
	callAjax(requestUrl, StateChangeHandlerforErrorLog);
}
function StateChangeHandlerforErrorLog() {
	if (XmlHttpObj.readyState == 4) {
	}

}
function setLanguage(id,filename) {
    sourcefile = filename;
	var requestUrl;
	requestUrl = "changeLanguage_action.php" + "?lid=" + encodeURIComponent('' + id);
	callAjax(requestUrl, StateChangeHandlerforChangeLang);
}

function StateChangeHandlerforChangeLang() {
	if (XmlHttpObj.readyState == 4) {
		if(XmlHttpObj.status == 200){	
			window.location.href =sourcefile;

		}

	}

}


//******************************************************//

//utility.js :: End

//******************************************************//

//******************************************************//

//dialogue_box.js :: Begin

//******************************************************//

// global variables //
var TIMER = 5;
var SPEED = 10;
var WRAPPER = 'content';

// calculate the current window width //
function pageWidth() {
  return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

// calculate the current window height //
function pageHeight() {
  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

// calculate the current window vertical offset //
function topPosition() {
  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

// calculate the position starting at the left of the window //
function leftPosition() {
  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

// build/show the dialog box, populate the data and call the fadeDialog function //
function showDialog(title,message,type,autohide) {
  if(!type) {
    type = 'error';
  }
  var dialog;
  var dialogheader;
  var dialogclose;
  var dialogtitle;
  var dialogcontent;
  var dialogmask;
  if(!document.getElementById('dialog')) {
    dialog = document.createElement('div');
    dialog.id = 'dialog';
    dialogheader = document.createElement('div');
    dialogheader.id = 'dialog-header';
    dialogtitle = document.createElement('div');
    dialogtitle.id = 'dialog-title';
    dialogclose = document.createElement('div');
    dialogclose.id = 'dialog-close'
    dialogcontent = document.createElement('div');
    dialogcontent.id = 'dialog-content';
    dialogmask = document.createElement('div');
    dialogmask.id = 'dialog-mask';
    document.body.appendChild(dialogmask);
    document.body.appendChild(dialog);
    dialog.appendChild(dialogheader);
    dialogheader.appendChild(dialogtitle);
    dialogheader.appendChild(dialogclose);
    dialog.appendChild(dialogcontent);;
    dialogclose.setAttribute('onclick','hideDialog()');
    dialogclose.onclick = hideDialog;
  } else {
    dialog = document.getElementById('dialog');
    dialogheader = document.getElementById('dialog-header');
    dialogtitle = document.getElementById('dialog-title');
    dialogclose = document.getElementById('dialog-close');
    dialogcontent = document.getElementById('dialog-content');
    dialogmask = document.getElementById('dialog-mask');
    dialogmask.style.visibility = "visible";
    dialog.style.visibility = "visible";
  }
  dialog.style.opacity = .00;
  dialog.style.filter = 'alpha(opacity=0)';
  dialog.alpha = 0;
  var width = pageWidth();
  var height = pageHeight();
  var left = leftPosition();
  var top = topPosition();
  var dialogwidth = dialog.offsetWidth;
  var dialogheight = dialog.offsetHeight;
  var topposition = top + (height / 3) - (dialogheight / 2);
  var leftposition = left + (width / 2) - (dialogwidth / 2);
  dialog.style.top = topposition + "px";
  dialog.style.left = leftposition + "px";
  dialogheader.className = type + "header";
  dialogtitle.innerHTML = title;
  dialogcontent.className = type;
  dialogcontent.innerHTML = message;
  var content = document.getElementById(WRAPPER);
  dialogmask.style.height = content.offsetHeight + 'px';
  dialog.timer = setInterval("fadeDialog(1)", TIMER);
  if(autohide) {
    dialogclose.style.visibility = "hidden";
    window.setTimeout("hideDialog()", (autohide * 1000));
  } else {
    dialogclose.style.visibility = "visible";
  }
}

// hide the dialog box //
function hideDialog() {
  var dialog = document.getElementById('dialog');
  clearInterval(dialog.timer);
  dialog.timer = setInterval("fadeDialog(0)", TIMER);
}

// fade-in the dialog box //
function fadeDialog(flag) {
  if(flag == null) {
    flag = 1;
  }
  var dialog = document.getElementById('dialog');
  var value;
  if(flag == 1) {
    value = dialog.alpha + SPEED;
  } else {
    value = dialog.alpha - SPEED;
  }
  dialog.alpha = value;
  dialog.style.opacity = (value / 100);
  dialog.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(dialog.timer);
    dialog.timer = null;
  } else if(value <= 1) {
    dialog.style.visibility = "hidden";
    document.getElementById('dialog-mask').style.visibility = "hidden";
    clearInterval(dialog.timer);
  }
}


//******************************************************//

//dialogue_box.js :: End

//******************************************************//

