// JavaScript Document
//onclick="return getHtmlContent(this, 'GetContent');"
// Start Getting Elements Position 
var rightSidebarURL = "/";

var ajaxCallerObj = "";
var ns4 = document.layers;

function getElementLeft(Elem) {
	if (ns4) {
		return Elem.pageX;
	} 
	else {
		xPos = Elem.offsetLeft;
		tempEl = Elem.offsetParent;
  		while (tempEl != null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;
	}
}


function getElementTop(Elem) {
	if (ns4) {
		return Elem.pageY;
	} 
	else {
		yPos = Elem.offsetTop;
		tempEl = Elem.offsetParent;
		while (tempEl != null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
		return yPos;
	}
}
// End Getting Elements Position 

// Start getting current domain name 
function getServerName()
{
    var str = window.location.protocol + '//' + window.location.hostname;
    return str;
}
// End getting current domain name 

// Start For implemenying AJAX functinality we need to create HTTP object. function getHttpRequest() is used to create HTTP Object 

getHttpRequest = function() {
	// Gecko / IE7
	if (typeof(XMLHttpRequest) != 'undefined')
		return new XMLHttpRequest() ;
	// IE6
	try {return new ActiveXObject('Msxml2.XMLHTTP');}
	catch(e) {}
	// IE5
	try {return new ActiveXObject('Microsoft.XMLHTTP');}
	catch(e) {}
	return null ;
}

function loadUrl(urlToCall, callBackFunction)
{	
	urlToCall = urlToCall+'&'+Math.random();
	var oXmlHttp = getHttpRequest();
	oXmlHttp.open( "GET", urlToCall, true);
	oXmlHttp.onreadystatechange = function() {
		if ( oXmlHttp.readyState == 4 ) {
			/*if (oXmlHttp.status != 200 && oXmlHttp.status != 304) {
				alert( 'The server didn\'t send back a proper response. Please contact your system administrator.\n\n' +						'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')\n\n' +'Requested URL:\n' + urlToCall + '\n\n' + 'Response text:\n' + oXmlHttp.responseText );
				return ;
			}*/
			callBackFunction( oXmlHttp.responseText );
		}
	}
	oXmlHttp.send(null);
}


function loadUrlForAjaxSearch(urlToCall, callBackFunction)
{	
	urlToCall = urlToCall+'&'+Math.random();
	var oXmlHttp = getHttpRequest();
	
	oXmlHttp.onreadystatechange = function() {
		if( oXmlHttp.readyState == 4 ) {
			/*if (oXmlHttp.status != 200 && oXmlHttp.status != 304) {
				alert( 'The server didn\'t send back a proper response. Please contact your system administrator.\n\n' +						'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')\n\n' +'Requested URL:\n' + urlToCall + '\n\n' + 'Response text:\n' + oXmlHttp.responseText );
				return ;
			}*/
			callBackFunction( oXmlHttp.responseText );
		}
		else
		{
		document.getElementById('str_search_keyword').style.backgroundImage  = 'url(http://www.thedisabledshop.com/images/ajax_search_loading.gif)'; 
 		document.getElementById('str_search_keyword').style.backgroundRepeat= 'no-repeat';                    
 		document.getElementById('str_search_keyword').style.backgroundPosition = 'right';
		}
		
	}
	oXmlHttp.open( "GET", urlToCall, true);
	oXmlHttp.send(null);
}

// End For implementing AJAX functinality we need to create HTTP object. function getHttpRequest() is used to create HTTP Object 

// Start Page level functions 

function placeOverlay() {
	//document.getElementById('overlay').style.display='block';
document.getElementById('ajaxContentForProfile').innerHTML = "<div style='text-align:center;'><img src='../ajax_js/popup_window/images/loading.gif' /></div>";
//document.getElementById('overlay').style.height=(getElementTop(document.getElementById('height_finder'))+100)+'px';
}
function removeOverlay() {
	document.getElementById('overlay').style.display='none';
}

//overlay for back end
function placeOverlayBe() {
	document.getElementById('overlay_backend').style.display='block';
	document.getElementById('overlay_backend').style.height=(getElementTop(document.getElementById('height_finder'))+100)+'px';
}
function removeOverlayBe() {
	document.getElementById('overlay_backend').style.display='none';
}

function placeOverlayBeEmailDetails() {
	document.getElementById('overlayCheckoutDetails').style.display='block';
	document.getElementById('overlayCheckoutDetails').style.height=(getElementTop(document.getElementById('height_finder'))+100)+'px';
}
function removeOverlayBeEmailDetails() {
	document.getElementById('overlayCheckoutDetails').style.display='none';
}

//general fn for showing result
function showResult(htmlContent) {
	if(htmlContent.indexOf("{Error raised on server}") == -1)
	{
	}
	else{
	alert(htmlContent);
	}
	removeOverlay();
	//ajaxCallerObj.focus();
}

//general fn for showing result in a layer 
//not used in this context.
function showResultLayer(htmlContent) {
	if(htmlContent.indexOf("{Error raised on server}") == -1){
		showLayerWithTitle(ajaxCallerObj, 'nlAjaxLayer', -43, 15, 300, 'Notes');
		document.getElementById('nlLayerContent').innerHTML = htmlContent;
	}
	else {
		alert(htmlContent);
		removeOverlay();
	}
}


function closeAjaxPopup(nlAjaxLayer){
	document.getElementById('nlLayerContent').innerHTML = '';
	document.getElementById('nlAjaxLayer').style.display = 'none';
	//hideLayer(nlAjaxLayer);
	//removeOverlay();
	//alert(newpageaction);
}


//fn: to display the project details in a popup
function showProjectDetails(htmlContent) {
	if(htmlContent.indexOf("{Error raised on server}") == -1){
		showLayerWithTitle(ajaxCallerObj, 'nlAjaxLayer', -45, 5, 300, 'Project Details');
		document.getElementById('nlLayerContent').innerHTML = htmlContent;
		document.getElementById('nlAjaxLayer').style.display = 'inline';

	}
	else {
		alert(htmlContent);
		removeOverlay();
	}
}

//fn: to display the project details in a popup
function showProjectDetailsfrontend(htmlContent) {
	if(htmlContent.indexOf("{Error raised on server}") == -1){
		showLayerWithTitle(ajaxCallerObj, 'nlAjaxLayer', -45, 5, 300, 'Project Details');
		document.getElementById('nlLayerContent').innerHTML = htmlContent;
		document.getElementById('nlAjaxLayer').style.display = 'inline';

	}
	else {
		alert(htmlContent);
		removeOverlay();
	}
}

//fn: to display the project details in a popup
function showProjectDetails1(htmlContent) {
	if(htmlContent.indexOf("{Error raised on server}") == -1){
		showLayerWithTitle(ajaxCallerObj, 'nlAjaxLayer', 8, 60, 300, 'Project Details');
		document.getElementById('nlLayerContent').innerHTML = htmlContent;
		document.getElementById('nlAjaxLayer').style.display = 'inline';

	}
	else {
		alert(htmlContent);
		removeOverlay();
	}
}

function showProjectDetailsAdmin(htmlContent) {
	if(htmlContent.indexOf("{Error raised on server}") == -1){
		document.getElementById('projectDetials').innerHTML = htmlContent;
	}
	else {
		alert(htmlContent);
		removeOverlay();
	}
}

function showProjectDetailsAdmin1(htmlContent) {
	if(htmlContent.indexOf("{Error raised on server}") == -1){
		document.getElementById('projectDetails').innerHTML = htmlContent;
	}
	else {
		alert(htmlContent);
		removeOverlay();
	}
}

//fn: to collect the marker position according to the projects selected.
function clearTextAndSubmit(){
	document.getElementById('txt_x').value = "";
	document.getElementById('txt_y').value = "";
	var txt_x = document.getElementById('txt_x').value;
	var txt_y = document.getElementById('txt_y').value;
	var projectId = document.getElementById('sel_project').value;
	if(projectId > 0){
	loadUrl(getServerName() +projectUrl+"&projectId="+projectId+"&txt_x="+txt_x+"&txt_y="+txt_y+"&bit_map_size=1", show_image);
	}
	else{
		alert('Please select a project!');	
	}
	//frmSubmit();
}

//fn: to collect the marker position according to the projects selected.
function clearTextAndSubmit1(){
	document.getElementById('txt_x_small').value = "";
	document.getElementById('txt_y_small').value = "";
	var txt_x = document.getElementById('txt_x_small').value;
	var txt_y = document.getElementById('txt_y_small').value;
	var projectId = document.getElementById('sel_small_project').value;
	if(projectId > 0){
	loadUrl(getServerName() +projectUrl+"&projectId="+projectId+"&txt_x="+txt_x+"&txt_y="+txt_y+"&bit_map_size=0", show_small_image);
	}
	else{
		alert('Please select a project!');	
	}
	//frmSubmit();
}


//fn: to validate the form values
function validateForm(txt_x_id,txt_y_id){
	var txt_x = document.getElementById(txt_x_id).value;
	var txt_y = document.getElementById(txt_y_id).value;
	var message = "";
	if(txt_x != ""){
		if(!parseInt(txt_x)){
			message += 'Please enter a valid left position\n';
		}
	}
	else
	{
		message += 'Please enter left position\n';
	}
	if(txt_y != ""){
		if(!parseInt(txt_y)){
			message += 'Please enter a valid top position\n';
		}
	}
	else
	{
		message += 'Please enter a top position\n';
	}
	if(message != ""){
		alert(message);
		return false;
	}
	else{
		return true;
	}
}

//fn: to update the marker points
function submitFormValues(){
	var txt_x = document.getElementById('txt_x').value;
	var txt_y = document.getElementById('txt_y').value;
	var projectId = document.getElementById('sel_project').value;
	var h_xy = document.getElementById('h_browser').value;
	if(projectId > 0 && txt_x != "" && txt_y != ""){
		loadUrl(getServerName() +projectUrl+"&update=true&projectId="+projectId+"&txt_x="+txt_x+"&txt_y="+txt_y+"&h_xy="+h_xy+"&bit_map_size=1", showProjectDetailsAdmin);//show_image
	}
	else if(projectId <= 0){
		alert('Please select a project!');	
	}
	else if(txt_x == "" && txt_y == "")
		alert('Please mark a point on map!');
	
	
}

function submitFormValues1(){
	var txt_x = document.getElementById('txt_x_small').value;
	var txt_y = document.getElementById('txt_y_small').value;
	var projectId = document.getElementById('sel_small_project').value;
	var h_xy = document.getElementById('h_browser_small').value;
	if(projectId > 0 && txt_x != "" && txt_y != ""){
		loadUrl(getServerName() +projectUrl+"&update=true&projectId="+projectId+"&txt_x="+txt_x+"&txt_y="+txt_y+"&h_xy="+h_xy+"&bit_map_size=0", showProjectDetailsAdmin1);//show_image
	}
	else if(projectId <= 0){
		alert('Please select a project!');	
	}
	else if(txt_x == "" && txt_y == "")
		alert('Please mark a point on map!');
	
	
}

//fn: to display the details of project according to project id in the pop up
function showdetails(projectId){
	var obj = document.getElementById('marker'+projectId);
	ajaxCallerObj = obj;
	if(projectId > 0){
	loadUrl(getServerName() +projectUrl+"&details=true&projectId="+projectId+"&bit_map_size=1", showProjectDetails);
	}
	else{
		alert('Please select a project!');	
	}

}

function showdetailsfrontend(projectId){
	var obj = document.getElementById('marker'+projectId);
	ajaxCallerObj = obj;
	if(projectId > 0){
	loadUrl(getServerName() +projectUrlFrontend+"&details=true&projectId="+projectId+"&bit_map_size=1", showProjectDetailsfrontend);
	}
	else{
		alert('Please select a project!');	
	}

}
function showdetailssmall(projectId){
	var obj = document.getElementById('small_marker'+projectId);
	ajaxCallerObj = obj;
	if(projectId > 0){
	loadUrl(getServerName() +projectUrl+"&details=true&projectId="+projectId+"&bit_map_size=0", showProjectDetails1);
	}
	else{
		alert('Please select a project!');	
	}

}

//fn: to display project details for the admin user
function showAdminProjectDetails(projectId){
	if(projectId > 0){
	loadUrl(getServerName() +projectUrl+"&details=true&projectId="+projectId+"&bit_map_size=1", showProjectDetailsAdmin);
	}
	else{
		alert('Please select a project!');	
	}

}

//fn: to display project details for the admin user
function showAdminProjectDetails1(projectId){
	if(projectId > 0){
	loadUrl(getServerName() +projectUrl+"&details=true&projectId="+projectId+"&bit_map_size=0", showProjectDetailsAdmin1);
	}
	else{
		alert('Please select a project!');	
	}

}

function allMarkers(){
	loadUrl(getServerName() +projectUrl+"&allMarkers=true&bit_map_size=1", show_all_markers);

}

function allMarkerssmall(){close_map();
	loadUrl(getServerName() +projectUrl+"&allMarkers=true&bit_map_size=0", show_all_markers_small);

}
function allMarkersfrontend(){
	loadUrl(getServerName() +projectUrlFrontend+"&allMarkers=true&bit_map_size=1", show_all_markers_frontend);

}

function allMarkerssmallfrontend(){
	loadUrl(getServerName() +projectUrlFrontend+"&allMarkers=true&bit_map_size=0", show_all_markers_small_frontend);

}
// End Page level functions 




function showTheDisabledShopLayer(obj)
{
	ajaxCallerObj = obj;
	showLayerWithTitle(ajaxCallerObj, 'nlAjaxLayer', -15, 540, 300, 'Apply Discounts');
	document.getElementById('nlAjaxLayer').style.display = 'inline';
}
function closeAjaxPopupTheDisabledShopLayer(nlAjaxLayer){
	/*document.getElementById('nlLayerContent').innerHTML = '';*/
	document.getElementById('nlAjaxLayer').style.display = 'none';
	//hideLayer(nlAjaxLayer);
	//removeOverlay();
	//alert(newpageaction);
}

function showBrochureRequestForm(obj)
{
	ajaxCallerObj = obj;
	showLayerWithTitle(ajaxCallerObj, 'nlAjaxLayerBrochure', -10, 490, 300, 'Brochure Request');
	document.getElementById('nlAjaxLayerBrochure').style.display = 'inline';
}
function closeAjaxPopupTheDisabledShopLayerBrochure(nlAjaxLayer)
{
		document.getElementById('nlAjaxLayerBrochure').style.display = 'none';
}


function showLoginForm(obj)
{
	ajaxCallerObj = obj;
	showLayerWithTitle(ajaxCallerObj, 'nlAjaxLayerLogin', 20, 250, 300, 'Customer Login');
	document.getElementById('nlAjaxLayerForgotPassword').style.display = 'none';
	document.getElementById('nlAjaxLayerLogin').style.display = 'inline';
}
function closeLoginLayer(nlAjaxLayer){
	/*document.getElementById('nlLayerContent').innerHTML = '';*/
	document.getElementById(nlAjaxLayer).style.display = 'none';
	//hideLayer(nlAjaxLayer);
	//removeOverlay();
	//alert(newpageaction);
}

function showForgotPasswordForm(obj)
{
	ajaxCallerObj = obj;
	showLayerWithTitle(ajaxCallerObj, 'nlAjaxLayerForgotPassword', 20, 250, 300, 'Customer Forgot Passoword');
	document.getElementById('nlAjaxLayerLogin').style.display = 'none';
	document.getElementById('nlAjaxLayerForgotPassword').style.display = 'inline';	
}
function closeForgotPasswordLayer(nlAjaxLayerForgotPassword)
{
	document.getElementById(nlAjaxLayerForgotPassword).style.display = 'none';
}

function showTheDisabledShopLayerNewOffer(obj,id)
{
	ajaxCallerObj = obj;
	placeOverlayBe();
	document.getElementById('overlay_backend').innerHTML = "<div align='center'><img src='http://www.thedisabledshop.com/resource/image/front_end/popup_window/images/loading.gif' /></div>";
	loadUrl(getServerName() +rightSidebarURL+'ajax_product_details_action.php?Pid='+id+'&action=offerProductDetail',getTheDisabledShopLayerNewOfferProductDetails)
	
}
function closeAjaxPopupTheDisabledShopLayerNewOffer(nlAjaxLayer){
	document.getElementById('nlAjaxLayerNewOffer').style.display = 'none';
	removeOverlayBe();
	
}
function getTheDisabledShopLayerNewOfferProductDetails(htmlcontent)
{
	showLayerWithTitle(ajaxCallerObj, 'nlAjaxLayerNewOffer', -12, 45, 500, 'New Offer Discount');
	document.getElementById('nlAjaxLayerNewOffer').style.display = 'inline';
	document.getElementById('nlAjaxLayerOfferProductDetailsContent').innerHTML = htmlcontent;	
	document.getElementById('overlay_backend').innerHTML = '';
}


function showTheDisabledShopLayerProductDetail(obj,id)
{
	ajaxCallerObj = obj;
	placeOverlayBe();
	document.getElementById('overlay_backend').innerHTML = "<div align='center'><img src='http://www.thedisabledshop.com/resource/image/front_end/popup_window/images/loading.gif' /></div>";	
	loadUrl(getServerName() +rightSidebarURL+'ajax_product_details_action.php?Pid='+id+'&action=productDetail',getDisabledProductDetails)
	
}
function closeAjaxPopupTheDisabledShopLayerProductDetail(nlAjaxLayer){
	document.getElementById('nlAjaxLayerProductDetails').style.display = 'none';
	removeOverlayBe();
	
}
function closeAjaxPopupTheDisabledShopLayerMoreInformation(nlAjaxLayer){
	document.getElementById('nlAjaxLayerMoreInformation').style.display = 'none';
	removeOverlayBe();
	
}
function showTheDisabledShopLayerMoreInformation(obj)
{
	ajaxCallerObj = obj;
	placeOverlayBe();
	showLayerWithTitle(ajaxCallerObj, 'nlAjaxLayerMoreInformation', -200, 260, 500, 'What is Vat Exemption');
	document.getElementById('nlAjaxLayerMoreInformation').style.display = 'inline';
}
function getDisabledProductDetails(htmlcontent)
{
	showLayerWithTitle(ajaxCallerObj, 'nlAjaxLayerProductDetails', -15, 122, 724, 'Product Details');
	document.getElementById('nlAjaxLayerProductDetails').style.display = 'inline';
	//alert(htmlcontent);
	document.getElementById('nlAjaxLayerProductDetailsContent').innerHTML = htmlcontent;
	
	document.getElementById('overlay_backend').innerHTML = '';
	
}

//Ajax function to load search data using the search keyword

function loadSearchData(keyword,cat_id)
{
		
	//alert(keyword);
		//alert(cat_id);
//alert(window.event.keyCode);
	if(keyword != "" && keyword.length > 2)
	{
		loadUrlForAjaxSearch('/search_ajax_action.php?int_category_id='+cat_id+'&str_search_keyword='+keyword+'&action=searchAjax',getSearchAjaxDetails);
	}
}
function getSearchAjaxDetails(htmlcontent)
{
	//alert(htmlcontent);
	if(htmlcontent != '')
	{
		document.getElementById('selectAjaxSearchBoxDiv').style.display = 'inline';
		document.getElementById('str_search_keyword').style.backgroundImage  = 'none';
		document.getElementById('selectAjaxSearchBoxDiv').innerHTML = htmlcontent;
	}
	else
	{
		document.getElementById('str_search_keyword').style.backgroundImage  = 'none';
		document.getElementById('selectAjaxSearchBoxDiv').innerHTML =  '<div class=\"ajaxSearchItems\"><font color=\"#F00000\">No result found !!!</font></div>';	
	}
}

//Ajax fnction to search the details for the given email id

function searchajaxDetails(str_email_id)
{
		placeOverlayBeEmailDetails();
		document.getElementById('overlayCheckoutDetails').innerHTML = "<div align='center' style='padding-top:308px;'><img src='http://www.thedisabledshop.com/resource/image/front_end/popup_window/images/loadingDetails.gif' /></div>";
		//alert(str_email_id);
	if(str_email_id != '')
	{
		loadUrl('checkout_shipping.php?str_email_id='+str_email_id+'&action=searchAjaxCustomerDetails',getSearchAjaxCustomerDetails);
	}
	else
	{
		removeOverlayBeEmailDetails();
	}
}
function getSearchAjaxCustomerDetails(htmlcontent)
{
	if(htmlcontent !="" && htmlcontent == "Registered User")
	{
		document.getElementById('str_email').value = "";
		document.getElementById('str_ship_firstname').value = "";
		document.getElementById('str_ship_lastname').value = "";
		document.getElementById('str_ship_address1').value = "";
		document.getElementById('str_ship_address2').value = "";
		document.getElementById('str_ship_home_phone').value = "";
		document.getElementById('str_ship_zip').value = "";
		document.getElementById('str_bill_address1').value = "";
		document.getElementById('str_bill_address2').value = "";
		document.getElementById('str_bill_home_phone').value = "";
		document.getElementById('str_bill_zip').value = "";
		
		window.location = 'http://www.thedisabledshop.com/login/login.php?user=registered';
	}
	else if(htmlcontent !="" && htmlcontent != "Registered User")
	{
		document.getElementById('customerDetails').innerHTML = htmlcontent;	
	}
	else
	{
			document.getElementById('str_ship_firstname').value = "";
			document.getElementById('str_ship_lastname').value = "";
			document.getElementById('str_ship_address1').value = "";
			document.getElementById('str_ship_address2').value = "";
			document.getElementById('str_ship_home_phone').value = "";
			document.getElementById('str_ship_zip').value = "";
			document.getElementById('str_bill_address1').value = "";
			document.getElementById('str_bill_address2').value = "";
			document.getElementById('str_bill_home_phone').value = "";
			document.getElementById('str_bill_zip').value = "";
	}
	removeOverlayBeEmailDetails();
}
function updateStyle(obj)
{	
	var url = 'http://www.thedisabledshop.com/_top_action.php?act=textSize&style_size='+obj;
	url+='&no='+Math.random();
	var oXmlHttp = getHttpRequest();
	oXmlHttp.open( "GET", url, true);
	oXmlHttp.onreadystatechange = function() {
		if( oXmlHttp.readyState == 4 ) {
			
		}		
	}
	oXmlHttp.send(null);
}
