
/*
*
*  hide and show div
*  must have an unique name, which means there is no element has the same id or NAME!
*/

function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "block";
}
function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
if(document.getElementById(d).style.display == "none" || document.getElementById(d).style.display=="") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}

function HideContentVisibility(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.visibility = "hidden";
}
function ShowContentVisibility(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.visibility = "visible";
}

function ReverseContentVisibility(d) {
if(d.length < 1) { return; }
if(document.getElementById(d).style.visibility == "hidden" || document.getElementById(d).style.visibility=="") { document.getElementById(d).style.visibility = "visible"; }
else { document.getElementById(d).style.visibility = "hidden"; }
}
/*
*
*  end hide and show div
*/

/*
*
*  add and remove div
*/
function addEvent(myDiv,theValue,divName,arrayName)
{
var ni = document.getElementById(myDiv);
var numi = document.getElementById(theValue);
var num = (numi.value -1)+ 2;
numi.value = num;
var divIdName = divName+num;
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);
//newdiv.innerHTML = "Element Number "+num+" has been added! <a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\')\">Remove the div &quot;"+divIdName+"&quot;</a>";
newdiv.innerHTML = "<input type=\"text\" name=\""+arrayName+"[]\" />&nbsp;&nbsp;<a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\',\'"+myDiv+"\')\">"+REMOVE+"</a>";

ni.appendChild(newdiv);
}

function removeEvent(divNum,myDiv)
{
var d = document.getElementById(myDiv);
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
}
/*
*
*  end add and remove div
*/


function inArray(needle, haystack){
  for (h in haystack) {
  if (haystack[h] == needle) {
  return true;
  // return h;
  }
}

return false;
} 

function goToPage(page){
	if (page != "" ) {
		if (page != "--" ) {
			window.location.href = page;
		}
	}
	return false;
}

function Check(obj,action) {
	var i=0;
	
    while(true){
        var myObjID=obj+i;
        var box=document.getElementById(myObjID);
        
        if(box){
        	//check or uncheck the box
        	box.checked=action;
        }
        else
        	break;
        
        i++;
    }

}


  function getObjValues(obj) {
	var i=0;
	var Values="";
	var MyObj;
	
    while(true){
        //clear history
        MyObj="";
        MyObj=obj+i;
        MyObj=document.getElementById(MyObj);
        
        if(MyObj){
        	if(MyObj.value){
        	    if(Values!="")
        	      Values+=";";
        	    
        	    Values+=MyObj.value;
        	}
        }else
        	break;
        
        i++;
    }
    
    return Values;

  }

  function getTextValue(id) {
        MyObj=document.getElementById(id);
        
        if(MyObj){
			return MyObj.value;
    	}
  }
  
  /*
  *get selected items from multple dropdown
  */
  function getMultiple(ob) {
    var selected = new Array();
    var ob=document.getElementById(ob);
    for (var i = 0; i < ob.options.length; i++) 
      if (ob.options[ i ].selected) 
        selected.push(ob.options[ i ].value);
    
    return selected;
  }
  
  function getStrFromArray(arr,separator){
  	  var amount=arr.length;
      var str="";
      for(i=0;i<amount;i++){
          if(str!="")
            str+=separator;
          
          str+=arr[i];
      }
      return str;
  }

function goTo (page) {
/* This function is called from the navigation menu
   to jump to the designated URL. Empty values
   are ignored and "--" indicates a menu seperator    */
   
	if (page != "" ) {
		if (page == "--" ) {
			resetMenu();
		} else {
			document.location.href = page;
		}
	}
	return false;
}

function resetMenu () {
/* Resets the menu to the specified menu item           */   
	document.gmenu.page.options[0].selected = true;
}

/*
 * disable/enable select
 */
 function DisableSelect(id,disableIt)
{  
	var obj=document.getElementById(id);
	obj.disabled = !disableIt;
}

function confirmSubmit(myLocation)
{
var agree=confirm("Do you really want to delete?");
if (agree){
    location.href = myLocation;
	return true ;
}
else{
	return false ;
}


}

  function getSelectedValue(id){
  	var obj=document.getElementById(id);
    var selIndex = obj.selectedIndex;
	var SelectedValue = obj.options[selIndex].value;
	return SelectedValue;
  }	  

function URLDecode(psEncodeString)
{
  // Create a regular expression to search all +s in the string
  var lsRegExp = /\+/g;
  // Return the decoded string
  return unescape(String(psEncodeString).replace(lsRegExp, " "));
}


function getSelectedCheckBox(CheckBoxName,CheckBoxValueObj) {
	var i=0;
	var str="";
	
    while(true){
        var box=document.getElementById(CheckBoxName+i);
        
        if(box){
        	if(box.checked){
        	  //generate ids
        	  var ValueObj=document.getElementById(CheckBoxValueObj+i);
        	  if(ValueObj){
        	    if(str!="")
        	      str+=",";
        	    str+=ValueObj.value;    	    
        	  }
        	}
        }
        else{
        	break;
        }
        i++;
    }
    //alert(str);
    return str;

}


function isEqual(elem1,elem2){

	if(elem1.value!=elem2.value){

	  alert("Sorry, the passwords are not equal.");

	  return false;

	}else

		return true;

}

//for detail page
function getAltImg(Action){
	var AllImgs=getAllImages();
	var CurrentImg= document.getElementById("bigImg");
	var CurrentImgSrc=CurrentImg.src;
	
	var amount = AllImgs.length;
	var CurrentPos,ActionPos;
	
    for (i=0; i<amount; i++) {    	
    	
    	if(CurrentImgSrc.indexOf(AllImgs[i])>0){
    		CurrentPos=i;
    		break;
    	}
    }
    
    if(Action=="previous"){
    	if(CurrentPos==0)
    		//go to last image
    		ActionPos=amount-1;
    	else
    	    ActionPos=(CurrentPos-1)%amount;
    }else if(Action=="next")
    	ActionPos=(CurrentPos+1)%amount;
    
    //change current image
    var ImgToBe=AllImgs[ActionPos];
    if(ImgToBe)
    	CurrentImg.src=ImgToBe;
    	
}

function gotoURL(selObj,URL) {

    var selObj = document.getElementById(selObj);

    var selIndex=selObj.selectedIndex;

    var selValue=selObj.options[selIndex].value;

    var targetPage=URL+selValue;
    
    //sort items
    if(selValue!=""){
        window.location.href=targetPage;
    }

    return true;
}
/*
function shippingMethods(selObj) {
    var selObj = document.getElementById(selObj);

    var index1=selObj.selectedIndex;

    var condition=selObj.options[index1].value;

    var targetPage="/cart/?ShippingID="+condition;
    
    //sort items
    if(condition!=""){
        window.location.href=targetPage;
    }

    return true;
}*/

function refresh(){
	var sURL = unescape(window.location.pathname);
	window.location.href = sURL;
}

	function ReloadCaptcha(){
		img = document.getElementById('Captcha');
		img.src = '/Component/visual-captcha.php?' + Math.random();
	}
	
	function ChanageStyle(id,MyStyle) {
		document.getElementById(id).style = MyStyle;
	}
	
	function PrintThisPage(){
		window.print();
	}
	
	function AddToBookmarks (){ 

 url = self.location.href; 

 title = document.title;
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }

	}