function couponpopupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=450,height=280,screenX=150,screenY=150,top=150,left=150')
}

function popupOrder(url) {
  window.open(url,'popupWindow','toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=600,height=400,screenX=150,screenY=150,top=150,left=150')
}

var a=1;
var tab1;
var tab2;
var brands;
var category;
function click1(){	
  tab1 = document.getElementById('tab1');
  tab2 = document.getElementById('tab2');
  brands = document.getElementById('brands');
  category = document.getElementById('category');
	tab1.style.background="url(images/tab1a.jpg)";
	category.style.display="block";
	tab2.style.background="url(images/tab2.jpg)";  
	brands.style.display="none";
	tab1.style.cursor="default"; tab1.style.cursor="default";
	tab2.style.cursor="hand"; tab2.style.cursor="pointer";
	a=2;
}
function click2(){
  tab1 = document.getElementById('tab1');
  tab2 = document.getElementById('tab2');
  brands = document.getElementById('brands');
  category = document.getElementById('category');

	tab2.style.background="url(images/tab2a.jpg)";
	brands.style.display="block";
	tab1.style.background="url(images/tab1.jpg)";  
	category.style.display="none";
	tab1.style.cursor="hand"; tab1.style.cursor="pointer";
	tab2.style.cursor="default"; tab2.style.cursor="default";
	a=2;
}
function on1(){	
  tab1 = document.getElementById('tab1');
  tab2 = document.getElementById('tab2');

//	tab1.style.background="url(images/tabactiv.gif)"; 
	if (a==1) {tab2.style.cursor="hand"; tab2.style.cursor="pointer";}
}
function on2(){
  tab1 = document.getElementById('tab1');
  tab2 = document.getElementById('tab2');

//	headTab2.style.background="url(images/tabactiv.gif)"; 
	if (a==1) {tab2.style.cursor="hand"; tab2.style.cursor="pointer";}
}
function out1(){
	if (a==2){
//		tab1.style.background="url(images/tab.gif)";
	}
}
function out2(){
	if (a==1){
//		tab2.style.background="url(images/tab.gif)";
	}
}

var hide_active = 0
function hideMenu() {
  if (hide_active > 0) {
    document.getElementById('menu' + hide_active).style.display="none";
  }
}

function on(a){
  if (hide_active == a) hide_active = 0;
  else hideMenu();
  if (a==1)  {document.getElementById('menu1').style.display="block";}
	if (a==2)  {document.getElementById('menu2').style.display="block";}
	if (a==3)  {document.getElementById('menu3').style.display="block";}
	if (a==4)  {document.getElementById('menu4').style.display="block";}
	if (a==5)  {document.getElementById('menu5').style.display="block";}
	if (a==6)  {document.getElementById('menu6').style.display="block";}
	if (a==7)  {document.getElementById('menu7').style.display="block";}
	if (a==8)  {document.getElementById('menu8').style.display="block";}
	if (a==9)  {document.getElementById('menu9').style.display="block";}
	if (a==10) {document.getElementById('menu10').style.display="block";}
	if (a==11) {document.getElementById('menu11').style.display="block";}
	if (a==12) {document.getElementById('menu12').style.display="block";}

}
function out(a) {
  hide_active = a;
  window.setTimeout("hideMenu()", 100);
}

function clickn(a){
	for (i=1;i<=20;i++){
    var cObj = document.getElementById("tab_"+i);
    if (cObj != null && cObj != undefined){
  		document.getElementById("tab_"+i).style.display="none";
  		document.getElementById("tab"+i+"HeadLeft").style.background="url(images/tab/tabheadleft.gif) bottom no-repeat";
  		document.getElementById("tab"+i+"Head").style.background="#ff7500 url(images/tab/tabhead.gif) bottom repeat-x";
  		document.getElementById("tab"+i+"HeadRight").style.background="url(images/tab/tabheadright.gif) bottom no-repeat";
  		document.getElementById("tab"+i+"Head").style.cursor="hand";
  		document.getElementById("tab"+i+"Head").style.cursor="pointer";
  		if (a==i) {
  			document.getElementById("tab_"+i).style.display="block";
  			document.getElementById("tab"+i+"HeadLeft").style.background="url(images/tab/tabheadlefta.gif) bottom no-repeat";
  			document.getElementById("tab"+i+"Head").style.background="#316496 url(images/tab/tabheada.gif) bottom repeat-x";
  			document.getElementById("tab"+i+"HeadRight").style.background="url(images/tab/tabheadrighta.gif) bottom no-repeat";
  			document.getElementById("tab"+i+"Head").style.cursor="default";
  		}
    }
	}
}



var IS_OVERVIEW = false;
var POS_TYPE = '2';
var bv = navigator.userAgent.toLowerCase().match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)[1];
var userAgentPopUp = navigator.userAgent.toLowerCase();
var bt_msie = /msie/.test(userAgentPopUp) && !/opera/.test(userAgentPopUp);
var bt_mozilla  = /mozilla/.test(userAgentPopUp) && !/(compatible|webkit)/.test(userAgentPopUp);
var	bt_safari = /webkit/.test(userAgentPopUp);
var	bt_opera = /opera/.test(userAgentPopUp);
var quickview = null;
var boxModel = !bt_msie || document.compatMode == "CSS1Compat";


function getOffsetInfoDiv(cObj, margin, border, padding, scroll) {
	var x = 0, y = 0, elem = cObj, parent = cObj, absparent=false, relparent=false, op, sl = 0, st = 0
  //, options = jQuery.extend({ margin: true, border: true, padding: false, scroll: true }, options || {});
	do {
		x += parent.offsetLeft || 0;
		y += parent.offsetTop  || 0;

		// Mozilla and IE do not add the border
		if (bt_mozilla || bt_msie) {
			// get borders
			var bt = parseInt(parent.style.borderTopWidth) || 0;
			var bl = parseInt(parent.style.borderLeftWidth) || 0;

			// add borders to offset
			x += bl;
			y += bt;

			// Mozilla removes the border if the parent has overflow property other than visible
			if (bt_mozilla && parent != elem && parent.style.overflow != 'visible') {
				x += bl;
				y += bt;
			}
			
			// Mozilla does not include the border on body if an element isn't positioned absolute and is without an absolute parent
			if (parent.style.position == 'absolute') absparent = true;
			// IE does not include the border on the body if an element is position static and without an absolute or relative parent
			if (parent.style.position == 'relative') relparent = true;
		}

		if (scroll) {
			// Need to get scroll offsets in-between offsetParents
			op = parent.offsetParent;
			do {
				sl += parent.scrollLeft || 0;
				st += parent.scrollTop  || 0;

				parent = parent.parentNode;

				// Mozilla removes the border if the parent has overflow property other than visible
				if (bt_mozilla && parent != elem && parent != op && parent.style.overflow != 'visible') {
					x += parseInt(parent.style.borderLeftWidth) || 0;
					y += parseInt(parent.style.borderTopWidth) || 0;
				}
			} while (op && parent != op);
		} else
			parent = parent.offsetParent;

		if (parent && (parent.tagName.toLowerCase() == 'body' || parent.tagName.toLowerCase() == 'html')) {
			// Safari and IE Standards Mode doesn't add the body margin for elments positioned with static or relative
			if ((bt_safari || (bt_msie && boxModel)) && elem.style.position != 'absolute') {
				x += parseInt(parent.style.marginLeft) || 0;
				y += parseInt(parent.style.marginTop)  || 0;
			}
			// Mozilla does not include the border on body if an element isn't positioned absolute and is without an absolute parent
			// IE does not include the border on the body if an element is positioned static and without an absolute or relative parent
			if ( (bt_mozilla && !absparent) || 
			     (bt_msie && elem.style.position == 'static' && (!relparent || !absparent)) ) {
				x += parseInt(parent.style.borderLeftWidth) || 0;
				y += parseInt(parent.style.borderTopWidth)  || 0;
			}
			break; // Exit the loop
		}
	} while (parent);

	if ( !margin) {
		x -= parseInt(elem.style.marginLeft) || 0;
		y -= parseInt(elem.style.marginTop)  || 0;
	}

	// Safari and Opera do not add the border for the element
	if ( border && (bt_safari || bt_opera) ) {
		x += parseInt(elem.style.borderLeftWidth) || 0;
		y += parseInt(elem.style.borderTopWidth)  || 0;
	} else if ( !border && !(bt_safari || bt_opera) ) {
		x -= parseInt(elem.style.borderLeftWidth) || 0;
		y -= parseInt(elem.style.borderTopWidth)  || 0;
	}

	if ( padding ) {
		x += parseInt(elem.style.paddingLeft) || 0;
		y += parseInt(elem.style.paddingTop)  || 0;
	}

	// Opera thinks offset is scroll offset for display: inline elements
	if (scroll && bt_opera && elem.style.display == 'inline') {
		sl -= elem.scrollLeft || 0;
		st -= elem.scrollTop  || 0;
	}

	var returnValue = scroll ? { top: y - st, left: x - sl, scrollTop:  st, scrollLeft: sl } : { top: y, left: x };

	return returnValue; 
};

function fixIEDiv(cObj, top, left, width, height, opacity, src) {

    html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+src+'" style="display:block;position:absolute;z-index:-1;'+
             (opacity !== false?'filter:Alpha(Opacity=\'0\');':'') +
			       'top:'+(top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':top)+';' +
			       'left:'+(left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':left) + ';' +
			       'width:'+(width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':width) + ';' +
			       'height:'+(height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':height) + ';' +
			'"/>';
    cObj.insertBefore( document.createElement(html), cObj.firstChild );
}

function	inArray( b, a ) {
		for ( var i = 0, al = a.length; i < al; i++ )
			if ( a[i] == b )
				return i;
		return -1;
}

function has( t, c ) {
	return inArray( c, (t.className || t).toString().split(/\s+/) ) > -1;
}

function addClass(id, cur){
  var cObj = document.getElementById(id);
  if (cObj != null && cObj != undefined) {
    if (!has(cObj, cur)) {
      cObj.className += ( cObj.className ? " " : "" ) + cur;
    }
  }
}

function removeClass ( id, c ) {
  var cObj = document.getElementById(id);
  if (cObj != null && cObj != undefined && c != undefined) {
    var re = new RegExp(c, "gi");
    cObj.className = cObj.className.replace(c, '');
	}
}

function show_quickview(element, url)
{
	//Anzeige-Optionen der Quickview; Laden des richtigen BGs, setzen der Position relativ zum Bild etc

	IS_OVERVIEW = false;
  var result = getOffsetInfoDiv(element, false, true, true, false);
	elemTop  = result['top'];
	elemLeft = result['left'];

  var site_width = 0;
  var site_height = 0;
  var pos_type_local = 2;
  if (bt_msie){
    site_width = document.documentElement.clientHeight * 1
    site_height = document.documentElement.clientWidth * 1
  } else {
    site_width = window.innerWidth * 1;
    site_height = window.innerHeight * 1;
  }
  
  if ((elemTop + element.offsetHeight + 343) > site_height) {
    if ((elemLeft + element.offsetWidth + 270) > site_width) {
      pos_type_local = '3' 
    } else {
      pos_type_local = '1'
    }
  } else {
    if (elemLeft + element.offsetWidth + 270 > site_width) {
      pos_type_local = '4' 
    } else {
      pos_type_local = '2'
    }
  }
  
	for (var i=1; i<=4; i++ ) 
	{
		if (i == pos_type_local)
		{
      addClass('quickview_box', 'quickview_box_type_' + pos_type_local);
      addClass('quickview_shadow', 'quickview_shadow_type_' + pos_type_local);
		}
		else
		{
      removeClass('quickview_box', 'quickview_box_type_' + i);
      removeClass('quickview_shadow', 'quickview_shadow_type_' + i);
		}
	}

  
//	var result = eval($(element).offset({ border: true, padding: true }));
  
//  alert(elemTop + ' ' + elemLeft);
//	alert(pos_type_local);

	var from_left=0, from_top = 0; // Positions-VAR
	switch (pos_type_local)
	{
		case '2':
			from_left	=  elemLeft+ (element.offsetWidth);
			from_top 	=	elemTop - 30;
		break;

		case '3':
			from_left	= elemLeft-260;
			from_top 	=	elemTop-(280-(element.offsetHeight));
		break;

		case '4':
			from_left	= elemLeft-260 ;
			from_top 	=	elemTop - (element.offsetHeight) - 5;

		break;

		default:
			from_left	= 	elemLeft+ (element.offsetWidth-10);
			from_top 	= 	elemTop-(280-(element.offsetHeight));
		break;
	}
  if(bt_msie){
    from_left-=20;
  }

  document.getElementById('quickview').style.left = from_left + 'px';
  document.getElementById('quickview').style.top = from_top + 'px';
	
	quickview_time(element, url);
}

function hide_navigation_total(){
  if (IS_OVERVIEW == false) {
    document.getElementById('quickview').style.display = 'none';
  }
}

function hideSuggest(){
  IS_OVERVIEW = false;
  window.setTimeout("hide_navigation_total()", 250);
  
}

function unhideSuggest(){
  IS_OVERVIEW = true;
}


function quickview_time(element, url) {

  if ( bt_msie && parseInt(bv) <= 6 ) {
   var cObj = document.getElementById('quickview');
   fixIEDiv(cObj, 'auto', 'auto', 'auto', 'auto', true, 'javascript:false;');
  }
  var http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) {
          http_request.overrideMimeType('text/xml');
          // See note below about this line
      }
  } else if (window.ActiveXObject) { // IE
      try {
          http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
          try {
              http_request = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (e) {}
      }
  }

  if (!http_request) {
      alert('Giving up :( Cannot create an XMLHTTP instance )');
      return false;
  }


  http_request.onreadystatechange = function() { alertContents(http_request); };
  http_request.open('GET', url, true);
  http_request.send(null);  
  
  
}

function alertContents(http_request) {
  if (http_request.readyState == 4) {
    if (http_request.status == 200) {
  //                var xmlDoc = http_request.responseXML.documentElement;
        try {
          if (http_request.responseText != 'ERROR') {
            document.getElementById('quickview_inner_content').innerHTML = http_request.responseText;
            document.getElementById('quickview').style.display = 'block';
          } else {
            document.getElementById('quickview').style.display = 'none';
          }
        } catch (e) {
          document.getElementById('quickview').style.display = 'none';
        }
    }
  }
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function checkEMail(emailID){
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value) == false){
		emailID.focus();
		return false
	}
	return true
 }


var dialog;
var compare_sender;
 



function compareClick(element, url) {
  var http_request = false;
  var cForm = document.compare_form;
  var add = '';
  compare_sender = element;
  if (cForm != null && cForm != undefined) {
    var el = cForm.getElementsByTagName('input');
    for (var i=0;i<el.length;i++){
      if (el[i].type == 'checkbox' && el[i].checked) {
        if (add == '') {
          add += 'compare[]=' + el[i].value;
        } else {
          add += '&compare[]=' + el[i].value;
        }
      }
    }
  }
  if (url.indexOf('?') > 0) {
    url += '&' + add;
  } else {
    url += '?' + add;
  }
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) {
          http_request.overrideMimeType('text/xml');
          // See note below about this line
      }
  } else if (window.ActiveXObject) { // IE
      try {
          http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
          try {
              http_request = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (e) {}
      }
  }

  if (!http_request) {
      alert('Giving up :( Cannot create an XMLHTTP instance )');
      return false;
  }


  http_request.onreadystatechange = function() { alertCompareContents(http_request); };
  http_request.open('GET', url, true);
  http_request.send(null);  
}

function removeCompare(url) {
  var http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) {
          http_request.overrideMimeType('text/xml');
          // See note below about this line
      }
  } else if (window.ActiveXObject) { // IE
      try {
          http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
          try {
              http_request = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (e) {}
      }
  }

  if (!http_request) {
      alert('Giving up :( Cannot create an XMLHTTP instance )');
      return false;
  }


  http_request.onreadystatechange = function() { alertCompareContents(http_request); };
  http_request.open('GET', url, true);
  http_request.send(null);  
}

function alertCompareContents(http_request) {
  if (http_request.readyState == 4) {
    if (http_request.status == 200) {
  //                var xmlDoc = http_request.responseXML.documentElement;
         if(!dialog){ // lazy initialize the dialog and only create it once
          dialog = new Ext.BasicDialog("compare-dlg", { 
                  autoTabs:false,
                  width:800,
                  height:500,
                  shadow:true,
                  minWidth:300,
                  minHeight:250,
                  proxyDrag: true
          });
          dialog.addKeyListener(27, dialog.hide, dialog);
          //dialog.addButton('Submit', dialog.hide, dialog).disable();
          dialog.addButton('Close', dialog.hide, dialog);
        }
        
        try {
          if (http_request.responseText != 'ERROR') {
            document.getElementById('x-dlg-bd').innerHTML = http_request.responseText;
            //document.getElementById('quickview').style.display = 'block';
            dialog.show(compare_sender);
          } else {
            alert('Nothing to compare');
          }
        } catch (e) {
          alert('Nothing to compare');
        }
    }
  }
}
