/*************************************************************************************************************************************************
Purpose : Creating AJAX object and performaing the operation.
Created By : Jaiswar Vipin Kumar R. - 13th Nov 2008
Updated By : 

*************************************************************************************************************************************************/

var xmlHttp;
var OptionCode;
var strRequestProcessing = "";
var intTOtalNumberOfItem; 
var intxPosition , intYPosition , divIdCode;
strRequestProcessing="<TABLE BORDER='0' WIDTH='60%'><TR><TD ALIGN='CENTER'><IMG SRC='/en/images/progress-loader.gif'></TD></TR></TABLE>";

function doOpreation(strDestinationURL,optionCodePass)
{ 
	xmlHttp=GetXmlHttpObject();
	OptionCode = optionCodePass;
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	 }
	var url="";
	url=strDestinationURL;
	//if(optionCodePass == 8)
	//	xmlHttp.onreadystatechange=stateChangedCart
	//else
		xmlHttp.onreadystatechange=stateChanged
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

/*************************************************************************************************************************************************
Purpose : Creating XMLHTTPRequest Object do perfrom the XMLHTTP communcation.
Input   : None.
Return  : XMLHTTPRequest Object.
*************************************************************************************************************************************************/
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
		{
			xmlHttp=new XMLHttpRequest();
		}
    catch (e)
		{
			 try
			  {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			  }
		 catch (e)
			  {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
		}
	return xmlHttp;
}

/*************************************************************************************************************************************************
Purpose : Remove the space.
Input   : Nobe.
Return  : Overrides the existing string trim function.
*************************************************************************************************************************************************/
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

/*************************************************************************************************************************************************
Purpose : Email address validation.
Input   : email addresss = [ strEmailAddress ].
Return  : true = valid email address , false = invalid email address.
*************************************************************************************************************************************************/
function validateEmailAddress(strEmailAddress)
{
	var str=strEmailAddress;
	var filter=/^.+@.+\..{2,3}$/

	if (filter.test(str))
		return(true);
	else 
		return(false); 
}
 
/*************************************************************************************************************************************************
Purpose : Adding item in the shopping cart. if session is not exists then simply redirect user to login the system.
Input   : ProductCode = [ pProductCode ],
		  User Code = [ userCode ].
Return  : None.
*************************************************************************************************************************************************/
function addingIetmInShoppingCart(pProductCode,userCode,pQuantity)
{
	doOpreation("<?php echo $_STR_SERVER_NAME?>ajaxOpreation.php?opreation=8&userCode="+userCode+"&productCode="+pProductCode+"&productQuantity="+document.getElementById(pQuantity).value,8);
}

/*************************************************************************************************************************************************
Purpose : Calculation of the item row price.
Input   : pQuantity = [ Selected Quantity ],
		  pUnitPrice = [ Product Unit Price ], 
		  pRowTotal = [ Row Total ].
Return  : product sum.
*************************************************************************************************************************************************/
function calculateRowPrice(pQuantity , pUnitPrice , pRowTotal , pCurrencySymbole)// , pSubTotal , pShippingCharges , pDiscountAmount , pGrandTotal)
{
	document.getElementById(pRowTotal).innerHTML = pCurrencySymbole+" " + (pQuantity * getCost(document.getElementById(pUnitPrice).innerHTML)).toFixed(2);
	calculateShoppingCartPrice(document.getElementById('txtNumberOfItem').value , pCurrencySymbole);
}

/*************************************************************************************************************************************************
Purpose : Calculating Shopping cart Footer.
Input   : Total number of items = [ pTotalnumberOfItem ],
		: Currency Submole = [pCurrencySymbole].
Return  : Shopping Cart Footer Sum.
*************************************************************************************************************************************************/
function calculateShoppingCartPrice(pTotalnumberOfItem , pCurrencySymbole)
{
	var strRowTotal , dblSubTotal , dblShippingAmount , dblDiscountAmount , dblGrandTotal , dblShowFooter;
	 
	dblSubTotal = 0;
	dblGrandTotal = 0
	dblShowFooter = document.getElementById("txtShowFooter").value;
	if(pTotalnumberOfItem == "")
		intTOtalNumberOfItem = document.getElementById('txtNumberOfItem').value;
	else
		intTOtalNumberOfItem = pTotalnumberOfItem;
	
	for(var intCounterForLoop = 1 ; intCounterForLoop <= intTOtalNumberOfItem; intCounterForLoop++)
	{
		strRowTotal = "divTotal"+intCounterForLoop;
		dblSubTotal = dblSubTotal + parseFloat(getCost(document.getElementById(strRowTotal).innerHTML));
	}
	
	document.getElementById('divSubTotal').innerHTML = pCurrencySymbole+" " + dblSubTotal.toFixed(2);

	if(intTOtalNumberOfItem == -1)
	{
		dblSubTotal = getCost(document.getElementById('divSubTotal').innerHTML);

		if(document.getElementById('divShippingCharges').innerHTML == "")
			{
				document.getElementById('divShippingCharges').innerHTML = pCurrencySymbole+" 0.00";
				dblShippingAmount = 0;
			}
		else
			dblShippingAmount  = getCost(document.getElementById('divShippingCharges').innerHTML);

		if(document.getElementById('divDiscountAmount').innerHTML == "")
			{
				document.getElementById('divDiscountAmount').innerHTML = pCurrencySymbole+" 0.00";
				dblDiscountAmount = 0;
			}
		else
			dblDiscountAmount = getCost(document.getElementById('divDiscountAmount').innerHTML);

	 
			dblGrandTotal = ((parseFloat(dblSubTotal) + parseFloat(dblShippingAmount)) - parseFloat(dblDiscountAmount)) ;
	
		document.getElementById('divGrandTotal').innerHTML = pCurrencySymbole+" " + (dblGrandTotal).toFixed(2);
	}
}

/*************************************************************************************************************************************************
Purpose : Getting nueric value from string.
Input   : pValue = [ passed value ].
Return  : Numeric digit.
*************************************************************************************************************************************************/
function getCost(pValue)
{
	var strCost;
	strCost = pValue;
	return((strCost.substring(2)).trim());
}
/*************************************************************************************************************************************************
Purpose : Adding selected item in shopping cart.
Input   : pProductCode = [ Product Code ],
	      pQuantyty = [ Quantity ],
		  pDivObject  = [ Div Object Id to display the message ]
Return  : Numeric digit.
*************************************************************************************************************************************************/
function addItemInShoppingCart(pProductCode , pQuantity , pDivObject)
	{
		divIdCode = pDivObject;
		doOpreation("/en/ajaxOpreation.php?opreation=8&productCode="+pProductCode+"&productQuantity="+pQuantity,2);
	}
function addItemInShoppingCartOther(pProductCode , pQuantity , pDivObject)
	{
		divIdCode = pDivObject;
		doOpreation("/en/ajaxOpreation.php?opreation=8&productCode="+pProductCode+"&productQuantity="+pQuantity+"&pDesgin=1",2);
	}
function setOtherOrderPanel()
{
		var strProductID;
		var intTotalNumberOfElement = (document.getElementById('hyudsyudsbc6484dchyff').value);
 
		for(var intCounter = 1 ; intCounter < intTotalNumberOfElement ; intCounter++)
		{
			strProductID = "divConformation"+intCounter;
			 
			if( divIdCode != strProductID)
				document.getElementById(strProductID).style.display="none";
			else
				document.getElementById(strProductID).style.display="block";
		}
}
function displayFloatingDiv(divId, title, width, height, left, top)
{
    DivID = divId;

    document.getElementById('dimmer').style.visibility = "visible";

    document.getElementById(divId).style.width = width + 'px';
    document.getElementById(divId).style.height = height + 'px';
    document.getElementById(divId).style.left = left + 'px';
    document.getElementById(divId).style.top = top + 'px';

    var addHeader , originalDivHTML;

    if (originalDivHTML == "")
        originalDivHTML = document.getElementById(divId).innerHTML;

    addHeader = '<table style="width:' + width + 'px" class="floatingHeader">' +
                '<tr><td ondblclick="void(0);" onmouseover="over=true;" onmouseout="over=false;" style="cursor:move;height:18px" class="normal_text">' + title + '</td>' +
                '<td style="width:18px" align="right"><a href="javascript:hiddenFloatingDiv(\'' + divId + '\');void(0);">' +
                '<img title="Close..." alt="Close..." src="images/close.jpg" border="0" /</a></td></tr></table>';


    // add to your div an header
    document.getElementById(divId).innerHTML = addHeader + originalDivHTML;


    document.getElementById(divId).className = 'dimming';
    document.getElementById(divId).style.visibility = "visible";
}

function handleEvent(oEvent) {
    intxPosition  = oEvent.screenX;
	intYPosition   = oEvent.screenY;	 
}

function showImage(pProductCode , pImageCounter)
{
	window.open("galleryImage.php?productCode="+pProductCode+"&imagecounter="+pImageCounter,"","location=0,status=1,scrollbars=0,width=800,height=650,resizable=0");
}

function setMenu(pObjetcCode, pAction)
{
	document.getElementById(pObjetcCode).style.display = pAction;
	
	if(pObjetcCode == "divSearch")
		window.setTimeout("hideSearch()", (15 * 1000));
}
function hideSearch()
{
	document.getElementById("divSearch").style.display = "none";
}
function checkingForSearchObject()
{
	var strSearchValue ;
	strSearchValue = document.getElementById("txtSearch").value;
	if(strSearchValue.trim() == "")
	{
		return false;
	}
}