function getFlashMovieObject(movieName){
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}
function SendDataToFlashMovie(movie_name, variable, value)
{
	var flashMovie=getFlashMovieObject(movie_name);
	if(flashMovie!=null){flashMovie.SetVariable("/:" + variable, value);}
}
function ReceiveDataFromFlashMovie(movie_name, variable)
{
	var flashMovie=getFlashMovieObject(movie_name);
	var message=flashMovie.GetVariable('/:'+variable);
	alert(message);
}


function _onmouseover(obj){
	img=obj.getElementsByTagName('img');
	img[0].style.display='none';
	img[1].style.display='block';
}
function _onmouseout(obj){
	img=obj.getElementsByTagName('img');
	img[0].style.display='block';
	img[1].style.display='none';
}
var fixPNG_arVersion = navigator.appVersion.split("MSIE")
var fixPNG_version = parseFloat(fixPNG_arVersion[1])
function fixPNG(myImage) 
{
    //return false;
	if ((fixPNG_version >= 5.5) && (fixPNG_version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
}
function CheckDateRange(from, to){if(Date.parse(from.value)<= Date.parse(to.value)){return true;}else{return false;}}
function IsValidDate(DateToCheck, FormatString) {
  var strDateToCheck;
  var strDateToCheckArray;
  var strFormatArray;
  var strFormatString;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var intDateSeparatorIdx = -1;
  var intFormatSeparatorIdx = -1;
  var strSeparatorArray = new Array("-"," ","/",".");
  var strMonthArray = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
  var intDaysArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

  strDateToCheck = DateToCheck.toLowerCase();
  strFormatString = FormatString.toLowerCase();
  
  if (strDateToCheck.length != strFormatString.length) {
    return false;
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strFormatString.indexOf(strSeparatorArray[i]) != -1) {
      intFormatSeparatorIdx = i;
      break;
    }
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strDateToCheck.indexOf(strSeparatorArray[i]) != -1) {
      intDateSeparatorIdx = i;
      break;
    }
  }

  if (intDateSeparatorIdx != intFormatSeparatorIdx) {
    return false;
  }

  if (intDateSeparatorIdx != -1) {
    strFormatArray = strFormatString.split(strSeparatorArray[intFormatSeparatorIdx]);
    if (strFormatArray.length != 3) {
      return false;
    }

    strDateToCheckArray = strDateToCheck.split(strSeparatorArray[intDateSeparatorIdx]);
    if (strDateToCheckArray.length != 3) {
      return false;
    }

    for (i=0; i<strFormatArray.length; i++) {
      if (strFormatArray[i] == 'mm' || strFormatArray[i] == 'mmm') {
        strMonth = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'dd') {
        strDay = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'yyyy') {
        strYear = strDateToCheckArray[i];
      }
    }
  } else {
    if (FormatString.length > 7) {
      if (strFormatString.indexOf('mmm') == -1) {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mm'), 2);
      } else {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mmm'), 3);
      }

      strDay = strDateToCheck.substring(strFormatString.indexOf('dd'), 2);
      strYear = strDateToCheck.substring(strFormatString.indexOf('yyyy'), 2);
    } else {
      return false;
    }
  }

  if (strYear.length != 4) {
    return false;
  }

  intday = parseInt(strDay, 10);
  if (isNaN(intday)) {
    return false;
  }
  if (intday < 1) {
    return false;
  }

  intMonth = parseInt(strMonth, 10);
  if (isNaN(intMonth)) {
    for (i=0; i<strMonthArray.length; i++) {
      if (strMonth == strMonthArray[i]) {
        intMonth = i+1;
        break;
      }
    }
    if (isNaN(intMonth)) {
      return false;
    }
  }
  if (intMonth > 12 || intMonth < 1) {
    return false;
  }

  intYear = parseInt(strYear, 10);
  if (isNaN(intYear)) {
    return false;
  }
  if (IsLeapYear(intYear) == true) {
    intDaysArray[1] = 29;
  }

  if (intday > intDaysArray[intMonth - 1]) {
    return false;
  }
  
  return true;
}

function IsLeapYear(intYear) {
  if (intYear % 100 == 0) {
    if (intYear % 400 == 0) {
      return true;
    }
  } else {
    if ((intYear % 4) == 0) {
      return true;
    }
  }

  return false;
}
function getTop(myObj)
{
	var top = 0;
	if (myObj.offsetParent) {
		top = myObj.offsetTop
		while (myObj = myObj.offsetParent) {
			top += myObj.offsetTop
		}
	}
	return top;
}
function getLeft(myObj)
{
 	var left = 0;
	if (myObj.offsetParent) {
		left = myObj.offsetLeft
		while (myObj = myObj.offsetParent) {
			left += myObj.offsetLeft
		}
	}
	return left;
}
function showMenu(divID,imgID,imgHover,offset)
{
	if(offset==undefined){offset=10;}
	if((x=findObj(imgID))!=null){
		document.SrSignature=x.src;x.src=imgHover;
		posX = getLeft(x);
		posY = getTop(x)+offset;
	}
	if((x=findObj(divID))!=null){
		x.style.left = posX +'px';
		x.style.top = posY +'px';
		x.style.display='block';	
	}
}
function hideMenu(divID,imgID)
{
	if((x=findObj(divID))!=null){x.style.display='none';}
	if ((x=findObj(imgID))!=null){x.src=document.SrSignature;}
}
function swapImgRestore(){var i,x,a=document.sr;for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;if ((x=findObj('imgTeks'))!=null){x.src=document.textImg}}function findObj(n,d){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=findObj(n,d.layers[i].document);if(!x && d.getElementById) x=d.getElementById(n);return x;}function swapImage(){var i,j=0,x,a=swapImage.arguments;document.sr=new Array;for(i=0;i<(a.length-2);i+=3)if ((x=findObj(a[i]))!=null){document.sr[j++]=x;if(!x.oSrc)x.oSrc=x.src; x.src=a[i+2];}if ((x=findObj('imgTeks'))!=null){document.textImg=x.src;x.src=a[3]}}
function MM_preloadImages(){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_swapImgRestore(){var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}function MM_findObj(n,d){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_swapImage(){var i,j=0,x,a=MM_swapImage.arguments;document.MM_sr=new Array;for(i=0;i<(a.length-2);i+=3)if((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;if(!x.oSrc)x.oSrc=x.src;x.src=a[i+2];}}function overview_show(section){for(i=0;i<overview_section.length;i++){if ((x=MM_findObj(overview_section[i]))!=null){x.style.display='none';}}if((x=MM_findObj(section))!=null){x.style.display='block';}}
function pop_modify_tab(){if(td_modify.style.display=="none"){td_modify.style.display="";img_modify_btn.src="images/btn_modify_ring_grey.gif";img_add_btn.src="images/spacer.gif";}else{td_modify.style.display="none";img_modify_btn.src="images/btn_modify_ring.gif";img_add_btn.src="images/btn_add_item.gif";}}
function getObject(obj) {
  var theObj;
  if(document.all) {
    if(typeof obj=="string") {
      return document.all(obj);
    } else {
      return obj.style;
    }
  }
  if(document.getElementById) {
    if(typeof obj=="string") {
      return document.getElementById(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}
function charCounter(txtBox,spanID,msg,maxChar) {
  var txtBoxObj=getObject(txtBox);
  var spanIDObj=getObject(spanID);
  var lenChar=maxChar - txtBoxObj.value.length;
  if(lenChar <= 0) {
    lenChar=0;
    msg='<span class="disable"> '+msg+' </span>';
    txtBoxObj.value=txtBoxObj.value.substr(0,maxChar);
  }
  spanIDObj.innerHTML = msg.replace("{CHAR}",lenChar);
}
function createRequestObject(){
	var request_o;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request_o = new XMLHttpRequest();
	}
	return request_o;
}
var fileLoadingImage = "images/loading.gif";
var fileLoadingImageHeight = 32;
function getContent(url,divID){
	/* The variable http will hold our new XMLHttpRequest object. */
	var divContainer="";
	var redirect_url="";	
	divContainer = divID;
	//document.getElementById(divContainer).style.height= fileLoadingImageHeight + 'px';
	if((x=MM_findObj(divContainer))!=null){
	x.innerHTML +='<div style="position:absolute;left:50%;top:50%;z-index:2;margin-left:-' + (fileLoadingImageHeight/2) + 'px;margin-top:-' + (fileLoadingImageHeight/2) + 'px;display:block;"><img src="' + fileLoadingImage + '" ></div>';
	}else{
		//setTimeout(function(){getContent(url,divID);});
	}
	var http = createRequestObject(); 	
	var queryStr="";

	a = getContent.arguments;	
	for(i=2;i<a.length;i++)
	{
		if(i==(a.length-1)) queryStr = queryStr + a[i];else queryStr = queryStr + a[i] + '&';
	}
	//alert(escape(queryStr).replace('%3D','='));
	//document.write(url + '?' + queryStr);
	//queryStr=escape(queryStr).replace(/\%3D/g,'=').replace(/\%26/g,'&').replace(/\%7B/g,'{').replace(/\%7D/g,'}');
	if(url.indexOf('?'))http.open('post', url + '&' + queryStr);else http.open('post', url + '?' + queryStr);
	
	/* Define a function to call once a response has been received.  */
	http.onreadystatechange = function(){
			/* Make sure that the transaction has finished. The XMLHttpRequest object 
			has a property called readyState with several states:
			0: Uninitialized
			1: Loading
			2: Loaded
			3: Interactive
			4: Finished */
		if(http.readyState == 1){
			//document.getElementById(divContainer).innerHTML = "Loading";
		}
		if(http.readyState == 4 && http.status == 200){ //Finished loading the response
			/* We have got the response from the server-side script,
				let's see just what it was. using the responseText property of 
				the XMLHttpRequest object. */
			var response = http.responseText;
			/* And now we want to change the product_categories <div> content.
				we do this using an ability to get/change the content of a page element 
				that we can find: innerHTML. */
			
			if(url.indexOf('create_account_content.php')>-1 && queryStr.indexOf('action')>-1){
				//document.write('url'+url+',query'+queryStr);
			}
			if(response.toString().indexOf('http://')==0 || response.toString().indexOf('https://')==0){
			document.write('<script language=javascript>window.location.href=\''+ response +'\'</script>')
			http.send(null);
			}
			if((x=MM_findObj(divContainer))!=null){
			x.innerHTML = response;}
			Lightbox.refresh();
			in_progress = false;
		}		
	} 
	/* Send the data.  */
	http.send(null);
}
function postContent(url,divID){
	/* The variable http will hold our new XMLHttpRequest object. */
	var divContainer="";
	var redirect_url="";
	var queryStr="";
	divContainer = divID;
	if((x=MM_findObj(divContainer))!=null){
	x.innerHTML +='<img src="' + fileLoadingImage + '" style="position:absolute;left:50%;top:50%;margin-left:-' + (fileLoadingImageHeight/2) + 'px;margin-top:-' + (fileLoadingImageHeight/2) + 'px;">';
	}else{
		//setTimeout(function(){postContent(url,divID);});
	}
	var http = createRequestObject(); 
	a = postContent.arguments;	
	for(i=2;i<a.length;i++)
	{
		if(i==(a.length-1)) queryStr = queryStr + a[i];else queryStr = queryStr + a[i] + '&';
	}	
	//if(url.indexOf('?'))http.open('post', url + '&' + queryStr);else http.open('post', url + '?' + queryStr);
	
	//document.write (url);
	//return false;
	//alert(divID);
	//alert('url' + url);
	//alert('queryStr' + queryStr);
	//queryStr=escape(queryStr).replace(/\%3D/g,'=').replace(/\%26/g,'&').replace(/\%7B/g,'{').replace(/\%7D/g,'}');
	//alert(queryStr);
	http.open('POST', url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
	http.setRequestHeader("Content-length", queryStr.length);
	http.setRequestHeader("Connection", "Keep-Alive");
	http.send(queryStr);

	/* Define a function to call once a response has been received.  */
	http.onreadystatechange = function(){
			/* Make sure that the transaction has finished. The XMLHttpRequest object 
			has a property called readyState with several states:
			0: Uninitialized
			1: Loading
			2: Loaded
			3: Interactive
			4: Finished */
		if(http.readyState == 1){
			//document.getElementById(divContainer).innerHTML = "Loading";
		}
		
		if(http.readyState == 4 && http.status == 200){ //Finished loading the response
			/* We have got the response from the server-side script,
				let's see just what it was. using the responseText property of 
				the XMLHttpRequest object. */
			var response = http.responseText;
			/* And now we want to change the product_categories <div> content.
				we do this using an ability to get/change the content of a page element 
				that we can find: innerHTML. */
			if(response.toString().indexOf('http://')==0||response.toString().indexOf('https://')==0){
			document.write('<script language=javascript>window.location.href=\''+ response +'\'</script>')
			http.send(null);
			}
			if((x=MM_findObj(divContainer))!=null){
			x.innerHTML = response;
			}
			Lightbox.refresh();
			in_progress = false;

			
		}		
	} 
}
String.prototype.trim = function(){return( this.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );}
function MM_swapTitle() { //v3.0
  var i,j=0,x,a=MM_swapTitle.arguments; document.MM_tl=new Array; for(i=0;i<(a.length-1);i+=2)	 
   if ((x=MM_findObj(a[i]))!=null){document.MM_tl[j++]=x; if(!x.oTl) x.oTl=x.title; x.title='';}
}
function MM_swapTtlRestore() { //v3.0
  var i,x,a=document.MM_tl; for(i=0;a&&i<a.length&&(x=a[i])&&x.oTl;i++){x.title=x.oTl;}
}
function set_anchor(link){
x='orori_link';
var anchorTag=document.createElement('a');anchorTag.appendChild(document.createTextNode(x));anchorTag.href = link; anchorTag.setAttribute('rel', "lightbox");
Lightbox.click(anchorTag);
}
function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}
function loadobjs(){
	if (!document.getElementById)
	return
	for (i=0; i<arguments.length; i++){
		var file=arguments[i]
		var fileref=""
		if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
			if (file.indexOf(".js")!=-1){ //If object is a js file
				fileref=document.createElement('script')
				fileref.setAttribute("type","text/javascript");
				fileref.setAttribute("src", file);
			}
			else if (file.indexOf(".css")!=-1){ //If object is a css file
				fileref=document.createElement("link")
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", file);
			}
		}
		if (fileref!=""){
			document.getElementsByTagName("head").item(0).appendChild(fileref)
			loadedobjects+=file+" " //Remember this object as being already added to page
		}
	}
}

function moveRightEdgeX(follower,banner_top_range){
	//alert('pret');
	//if ((follower_obj=MM_findObj(follower))!=null){
		follower_obj=document.getElementById(follower);
		if(isNS4){
			yMenuFrom=follower_obj.offsetTop;
			yMenuTo=windows.pageYOffset+banner_top_range;
		}else if(isDOM){	
			yMenuFrom=parseInt(follower_obj.offsetTop);
			yMenuTo=(isNS?window.pageYOffset:document.documentElement.scrollTop)+banner_top_range;
		}
		timeoutNextCheck=500;
		var today=new Date();
		//alert(yMenuFrom);
		//document.getElementById('watcher').innerHTML='From:'+yMenuFrom+', To'+yMenuTo;
		if(yMenuFrom!=yMenuTo && (yMenuTo>150 || yMenuTo<yMenuFrom)){
			yMenuTo=yMenuTo-170;
			yOffset=Math.ceil(Math.abs(yMenuTo-yMenuFrom)/20);
			if(yMenuTo < yMenuFrom)yOffset=-yOffset;
			if(isNS4){follower_obj.top+=yOffset;}
			else if(isDOM){
				follower_obj.style.top=(parseInt(follower_obj.offsetTop)+yOffset)+'px';
				timeoutNextCheck=10;
			}
		}
	//}
	setTimeout(function(){moveRightEdgeX(follower,banner_top_range)},10);
}

function modify_attribute(form_name, selection_name, attribute_selection){
	if(typeof(document.forms[form_name].elements[selection_name])!='undefined'){
		selection = document.forms[form_name].elements[selection_name];
		options_length = selection.length;
		for(i=0;i<options_length;i++){
			if(selection.options[i].text.replace(';def=true', '').replace(';def=false', '').replace(/ /g, '').toLowerCase()==attribute_selection.replace(/ /g, '').toLowerCase()){
				selection.selectedIndex = i;
				break;
			}
		}
	}
}
function populate_attributes(form_name){
	var product_id='';
	var form='';
	var attributes='';
	form=document.forms[form_name];
	product_id= form.elements['products_id'].value;
	el=form.elements;
	for(i=0;i<el.length;i++){
		if(el[i].type=='select-one'&&el[i].title!='Please select'){
			attributes+=el[i].name.replace('[','{').replace(']','}').replace('id','')+el[i].value;
		}
	}
	on_products_id=product_id+attributes;
}
function get_subtotal(form_name, item_groups){
	item_group=new Array();
	if(typeof(item_groups)=='string'){
		item_group[0]=item_groups;
	}else{item_group=item_groups;}
	
	form=document.forms[form_name];
	el=form.elements;
	subtotal=0;
	for(j=0;j<item_group.length;j++){
		for(i=0;i<5;i++){
			if(el[item_group[j]+'['+i+']']!=undefined){
				if(el[item_group[j]+'['+i+']'].checked){
					subtotal=subtotal+parseFloat(el['pc_'+item_group[j]+'['+i+']'].value);
				}
			}
		}
	}
	return subtotal;
}

//

/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/

var Url = {

    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}
function reset_section(split_name, owner, other)
{
	var teddy_ctnDiv = MM_findObj(split_name + '_ctn');
	if((x=MM_findObj(owner))!=null){
		if((y=MM_findObj(other))!=null){
			inspect_objects = y.getElementsByTagName('div');
			for(i=0, n=inspect_objects.length; i<n; i++){
				if(inspect_objects[i].id==split_name)
				{	
					if((label=MM_findObj(split_name + '_label'))!=null){label.style.display='none';}
					if((label=MM_findObj(split_name + '_roof'))!=null){label.style.display='none';}
					if((label=MM_findObj(split_name + '_floor'))!=null){label.style.display='none';}
					y.removeChild(inspect_objects[i]);
					break;
				}
			}
		}
	}
}


function hide_box(box_name)
{
	if((label=MM_findObj(box_name + '_label'))!=null){label.style.display='none';}
	if((label=MM_findObj(box_name + '_roof'))!=null){label.style.display='none';}
	if((label=MM_findObj(box_name + '_floor'))!=null){label.style.display='none';}
}
