/*=====================================================
# Author  : Prashant Lotlikar  @ Clarion Technologies
# File Name	: product_details.inc.php
# Version : 1.0.1
# Project : DisplayGear
# Client  : Richard
# Created by	: Prashant Lotlikar
# Created on	: 6 June 2007
# Last modified by : Prashant Lotlikar
# Last modified on : 6 June 2007

## THIS FILE IS SPECIFIC TO THE PRODUCT DETAILS SECTION ONLY  ##

#=====================================================  */

//  ======== PRELOAD IMAGES CODE COME HERE ===================
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_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}
//  ======== PRELOAD IMAGES CODE COME HERE ===================



function fn_isNumeric( val , msg){

		var objRegExp  = /^([1-9]+[0-9]*)$/;
		 var re = new RegExp(objRegExp);
		  if (val.value.match(re)) {
				return true;
		  }else{
				alert ( msg );
				val.focus();
		  }
}


//  ======== FUNCTION TO VALDIATE THE QUANTITY ENTERED BY THE USER ===================

function fnCheckQuantity()
{
	var1 = document.frmProductDetails.txtProductQuantity.value;
	var2 = document.frmProductDetails.txtGraphicQuantity.value;
	var3 = document.frmProductDetails.txtCombinedQuantity.value;

	if(var1 == '' && var2 == '' && var3 == '')
	{
		alert('Please enter quantity!');return false;
	}else
	{
		
		if(var1 != '') { if (! fn_isNumeric (document.frmProductDetails.txtProductQuantity, 'Please provide a valid product quantity!' ) ){	return false; } } 
		if(var2 != '') { if (! fn_isNumeric (document.frmProductDetails.txtGraphicQuantity, 'Please provide a valid graphic quantity!' ) ){	return false; } }
		if(var3 != '') { if (! fn_isNumeric (document.frmProductDetails.txtCombinedQuantity, 'Please provide a valid combined quantity!' ) ){	return false; } }
	}
}
//  ======== FUNCTION TO VALDIATE THE QUANTITY ENTERED BY THE USER ===================


//  ======== ALL THE POPUP WINDOW FUNCTIONS COME HERE  ===================

/*  FUNCTION TO OPEN THE ARTYWORK POPUP WINDOW  */
var popUpWin=0;
function popUpWindow(URLStr)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'ArtWorkDetails', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=yes,resizable=no,copyhistory=yes,width=200,height=150,left=200, top=200,screenX=200,screenY=200');
}

/*  FUNCTION TO OPEN THE PRODUCT DETAILS POPUP WINDOW  */
var popUpWin1=0;
function popUpWindow1(URLStr)
{
  if(popUpWin1)
  {
    if(!popUpWin1.closed) popUpWin1.close();
  }
  popUpWin1 = open(URLStr, 'Product_Details', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=650,height=500,left=100, top=200,screenX=100,screenY=200');
}


/*  FUNCTION TO OPEN THE PRODUCT ATTRIBUTE DETAILS POPUP WINDOW  */
var popUpWin2=0;
function popUpWindow2(URLStr)
{
  if(popUpWin2)
  {
    if(!popUpWin2.closed) popUpWin2.close();
  }
  popUpWin2 = open(URLStr, 'Product_Attribute_Details', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=500,height=300,left=200, top=200,screenX=200,screenY=200');
}

/*  FUNCTION TO OPEN THE PRODUCT ATTRIBUTE DESCRIPTION DETAILS POPUP WINDOW  */
var popUpWin3=0;
function popUpWindow3(URLStr)
{
  if(popUpWin3)
  {
    if(!popUpWin3.closed) popUpWin3.close();
  }
  popUpWin3 = open(URLStr, 'Product_Attribute_Description', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=600,height=500,left=100, top=100,screenX=100,screenY=100');
}

/*  FUNCTION TO OPEN THE WITHOUT SHOP DISTRIBUTOR PRICES POPUP WINDOW  */
var popUpWin4=0;
function popUpWindow4(URLStr)
{
  if(popUpWin4)
  {
    if(!popUpWin4.closed) popUpWin4.close();
  }
  popUpWin4 = open(URLStr, 'Without_Shop_Distributor_Prices', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=420,height=300,left=100, top=100,screenX=100,screenY=100');
}

//  ======== ALL THE POPUP WINDOW FUNCTIONS COME HERE  ===================




//--- CANVAS PRINT CODE COMES HERE
function  show_CanvasPrint(id , others)
{	
  	var strProductAttr = new Array() ;
	objProductAttr = document.frmProductDetails.elements['lstAttribute[]'];
	if(objProductAttr)
	{
		len = objProductAttr.length;
		if(len)
		{
			for(i=0;i<len;i++)
			{
				if(objProductAttr[i].value)
				{
					if( id != objProductAttr[i].value)
					{
						objProductAttr[i].value = '';						
					}					
				}
			}
		}
	}	//----End of  .........if(objProductAttr);
		
		
  var OtherCanvasPrints = others;
  var div_Message =  document.getElementById("div_Message");
  
  var OtherCanvasPrintsArray = OtherCanvasPrints.split(",");
  var ct = OtherCanvasPrintsArray.length ;
  var part_num=0;

  while (part_num < ct)
  {
    objOthersblock = document.getElementById("CanvasPrint_" + OtherCanvasPrintsArray[part_num]);
    objOthersblock.style.display='none';

    part_num+=1;
  }

  if(id)
  {
    var objblock ;
    //-- Show the print
    objblock = document.getElementById("CanvasPrint_" + id);
    objblock.style.display='block';        
    div_Message.style.display='none';    
  }else
  {
    var objblock ;
    objMainblock = document.getElementById("CanvasPrint");
    objMainblock.style.display='block';
    div_Message.style.display='block';    
  }
}
//--- CANVAS PRINT CODE COMES HERE


//	DYNAMIC PRICE GENERATION ...................

function show_price(pid,id,rangeid)
{
	// Set up the request
	//--get the product  attributes here ............
	var strProductAttr = new Array() ;
	objProductAttr = document.frmProductDetails.elements['lstAttribute[]'];
	if(objProductAttr)
	{

		len = objProductAttr.length;
		if(len)
		{
			for(i=0;i<len;i++)
			{
				if(objProductAttr[i].value)
				{
					strProductAttr[i] = objProductAttr[i].value ;
				}
			}
		}else
		{
			strProductAttr[0] = objProductAttr.value;
		}
	}	//----End of  .........if(objProductAttr);
	//--get the product  attributes here ............


	//--get the graphic  attributes here ............
	var strGraphicAttr = new Array() ;
	objGraphicAttr = document.frmProductDetails.elements['lstGraphicAttribute[]'];

	if(objGraphicAttr)
	{
		len = objGraphicAttr.length;
		if(len)
		{
			for(i=0;i<len;i++)
			{	if(objGraphicAttr[i].value)
				{
					strGraphicAttr[i] = objGraphicAttr[i].value ;
				}
			}
		}else
		{
			strGraphicAttr[0] = objGraphicAttr.value;
		}
	}	//--End of .........if(objGraphicAttr)
	//--get the graphic attributes here ............

	var xmlhttp = GetXmlHttpObject();

	if (xmlhttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	}

	function GetXmlHttpObject()
	{
		var xmlhttp=null;

		try
		{
			// Firefox, Opera 8.0+, Safari
			xmlhttp=new XMLHttpRequest();
		}
		catch (e)
		{
			// Internet Explorer
			try
			{
				xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}

		return xmlhttp;

	}

	xmlhttp.open('POST', 'product_details.php', true);

	// The callback function
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4)
		{
			if (xmlhttp.status == 200)
			{
				var ct;
				ct = xmlhttp.responseXML.getElementsByTagName('count')[0].firstChild.data;
				if(rangeid == 0){rangeid = '';}
				if(rangeid)
				{
					for(i=0;i<ct;i++)
					{
						var objProductDiv = document.getElementById("ProductDiv_" + i);
						var objGraphicDiv = document.getElementById("GraphicDiv_" + i);
						var objCombinedDiv = document.getElementById("CombinedDiv_" + i);

						//--DISTRIBUTORS WITH NO SHOP SITE
						var objRRPProductDiv = document.getElementById("RRPProductDiv_" + i);
						var objRRPGraphicDiv = document.getElementById("RRPGraphicDiv_" + i);
						var objRRPCombinedDiv = document.getElementById("RRPCombinedDiv_" + i);


						if(objProductDiv) { var product_price = xmlhttp.responseXML.getElementsByTagName('product_price')[i].firstChild.data;objProductDiv.innerHTML = unescape(product_price);}
						if(objGraphicDiv) { var graphic_price = xmlhttp.responseXML.getElementsByTagName('graphic_price')[i].firstChild.data;objGraphicDiv.innerHTML = unescape(graphic_price); 	}
						if(objCombinedDiv) { var combined_price = xmlhttp.responseXML.getElementsByTagName('combined_price')[i].firstChild.data;objCombinedDiv.innerHTML = unescape(combined_price); }

						//--DISTRIBUTORS WITH NO SHOP SITE
						if(objRRPProductDiv) { var rrp_product_price = xmlhttp.responseXML.getElementsByTagName('rrp_product_price')[i].firstChild.data;objRRPProductDiv.innerHTML = unescape(rrp_product_price);}
						if(objRRPGraphicDiv) { var rrp_graphic_price = xmlhttp.responseXML.getElementsByTagName('rrp_graphic_price')[i].firstChild.data;objRRPGraphicDiv.innerHTML = unescape(rrp_graphic_price); 	}
						if(objRRPCombinedDiv) { var rrp_combined_price = xmlhttp.responseXML.getElementsByTagName('rrp_combined_price')[i].firstChild.data;objRRPCombinedDiv.innerHTML = unescape(rrp_combined_price); }
					}
				}else
				{
						var objProductDiv = document.getElementById("ProductDiv" );
						if(objProductDiv) { var product_price = xmlhttp.responseXML.getElementsByTagName('product_price')[0].firstChild.data;objProductDiv.innerHTML =  unescape(product_price);}
				}
			}
		}
	}


	strisProductAttribute = document.frmProductDetails.hdnisProductAttribute.value;
	strisGraphicAttributeID = document.frmProductDetails.hdnisGraphicAttributeID.value;
	intXGraphic_product = document.frmProductDetails.intXGraphic_product.value;

	// Send the POST request
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	xmlhttp.send('chkSelectGraphic=' + id + '&dynamic=1&productid=' +  pid + '&hdnpost=1&hdnisProductAttribute=' + strisProductAttribute + '&hdnisGraphicAttributeID=' + strisGraphicAttributeID +'&lstGraphicAttribute=' + strGraphicAttr  + '&lstAttribute=' + strProductAttr + '&intXGraphic_product=' + intXGraphic_product +''  );

}

//	DYNAMIC PRICE GENERATION ...................

/* ==================================== END OF FILE ===========================================*/

