
//====================================================================================================
//	File Name		:	functions.js
//----------------------------------------------------------------------------------------------------

function popupWindowURL(url, winname,  w, h, menu, resize, scroll) {

    var x = (screen.width-w)/2;
    var y = (screen.height-h)/3;

	if (winname == null) winname = "newWindow";
	if (w == null) w = 800;
	if (h == null) h = 600;
	if (resize == null) resize = 1;

	menutype   = "nomenubar";
	resizetype = "noresizable";
	scrolltype = "noscrollbars";
	if (menu) menutype = "menubar";
	if (resize) resizetype = "resizable";
	if (scroll) scrolltype = "scrollbars";
	//alert(url+","+x+","+winname);
    cwin=window.open(url,winname,"top=" + y + ",left=" + x + ",screenX=" + x + ",screenY=" + y + "," + "status," + menutype + "," + scrolltype + "," + resizetype + ",width=" + w + ",height=" + h);

	if (!cwin.opener) cwin.opener=self;
	cwin.focus();

	return true;
}

function CheckUncheck_Click(fld, status)
{
	if(fld)
	{
		if(fld.length)
			for(i=0; i < fld.length; i++)
				fld[i].checked = status;
		else
			fld.checked = status;
	}
}

function Menu_ShowHide(menu, img, imgUp, imgDown)
{
	if(menu)
	{
		if(menu.style.display == 'none')
		{
			menu.style.visibility	= 'visible';
			menu.style.display		= 'block';
			img.src = imgUp;
			SetCookie(menu.id, 'open');
		}
		else
		{
			menu.style.visibility 	= 'hidden';
			menu.style.display 		= 'none';
			img.src = imgDown;
			SetCookie(menu.id, 'close');
		}
	}
}

function UploadImage_Change(obj, imgTag, defaultVal, defaultWidth)
{
	imgTag.width=120;

	if(obj.value == '')
		imgTag.src = defaultVal;
	else
	{
		imgTag.src = obj.value;
		if(defaultWidth != '')
			imgTag.width=defaultWidth;
	}
}

function SetTime()
{
	if(!document.getElementById('timeId'))	return;

	var Hours;
	var Mins;
	var Time;

	Stamp = new Date();

	Hours = Stamp.getHours();
	
	if (Hours >= 12)
		Time = " PM";
	else
		Time = " AM";
	
	if (Hours > 12)
		Hours -= 12;
	
	if (Hours == 0)
		Hours = 12;
	
	Mins = Stamp.getMinutes();

	if (Mins < 10)
		Mins = "0" + Mins;

	Sec = Stamp.getSeconds();
	if (Sec < 10)
		Sec = "0" + Sec;

	document.getElementById('timeId').innerHTML = ("&nbsp;" + Hours + ":" + Mins + ":" + Sec + Time);
}

setInterval('SetTime()',1000);

function getDate(parmDate)
{
	var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September","October", "November", "December");

	var curr_date = parmDate.getDate();

	var sup = "";

	if (curr_date == 1 || curr_date == 21 || curr_date ==31)
	{
	   sup = "st";
	}
	else if (curr_date == 2 || curr_date == 22)
	{
	   sup = "nd";
	}
	else if (curr_date == 3 || curr_date == 23)
	{
	   sup = "rd";
	}
	else
	{
	   sup = "th";
	}

	var curr_month 	= parmDate.getMonth();
	var curr_year 	= parmDate.getFullYear();

	return (curr_date + "<SUP>" + sup + "</SUP> " + m_names[curr_month] + " " + curr_year);
}

function GetCookie (name) 
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) 
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);

		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	}
	return null;
}

function SetCookie (name, value) 
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function convertnew_old(ln)
{
	var loc = document.location.toString();
	loc = loc.substring(7,loc.length);
	
	var newname = window.open('http://translate.google.com/translate_c?langpair=' + ln + "&u=" + document.location,"new_trans");
	newname.focus();
	return false;
	
	/*
	if (document.trans1.langpair.selectedIndex != 0)
	{
	var newname = window.open('http://translate.google.com/translate_c?langpair=' + document.trans1.langpair.value + "&u=" + document.location,"new_trans");
	newname.focus();
	return false;
	}
	else{
		alert('Kindly select a language.');
		document.trans1.langpair.focus();
	return false;
	}*/

}

function View_Prod()
{
	popupWindowURL('product_view.php?Action=Color&name='+document.mainpic.src,'','400','300','false','false','false');	
}

function OpenViewer(viewerId,productid)
{
	popupWindowURL('additional_image.php?prod_id='+productid+'&viewerId='+viewerId,'','400','300','false','false','false');	
}
function Language_Type(lang)
{
	document.forms[0].Language_Types.value = lang;
	document.forms[0].action = window.location.href;
	document.forms[0].submit();
}



function convertnew(pattern)
{
/////////////////////////////////////////////////////////////
// Script to use language convertor
// By Saradhi
/////////////////////////////////////////////////////////////

	/// Configuration parameters //////////////
	var open_in_same_window = 0;
	//////////// End Of Configuration /////////////

	var my_location = unescape(document.location.toString());
	var new_location ='';
	var new_pattern = '';
	if (my_location.indexOf('translate_c?') != -1) {
		/// From google...
		var indexof_u = my_location.indexOf('u=');
		if (indexof_u == -1) {
			new_location = document.location;
		}
		else {
			var subs = my_location.substring(indexof_u, my_location.length);
			var ss = subs.split('&');
			new_location = ss[0].substring(2, ss[0].length);
		}
	}
	else {
		new_location = document.location;
	}

	indexof_p = pattern.indexOf('|');

	var isen = '';
	if (indexof_p == -1) {
		indexof_p1 = pattern.indexOf('><');
		if (indexof_p1 == -1) {
			new_pattern = pattern;
			if (pattern == 'en') {
				isen = 1;
			}
		}
		else {
			var psplit =pattern.split('><');
			new_pattern = psplit[0]+'|'+psplit[1];
			if (psplit[1] == 'en') {
				isen = 1;
			}
		}
	}
	else {
		var psplit = pattern.split('|');
		new_pattern = psplit[0]+'|'+psplit[1];
		if (psplit[1] == 'en') {
			isen = 1;
		}
	}

	var thisurl = '';
	if (isen == 1) {
		thisurl = new_location;
	}
	else {
		thisurl = 'http://translate.google.com/translate_p?langpair=' + new_pattern + '&u=' + new_location;
	}
	if (open_in_same_window == 1) {
		window.location.href = thisurl;
	}
	else {
/*		if (CanAnimate ){
			msgWindow=window.open('' ,'subwindow','toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,menubar=yes,resizable=yes,left=0,top=0');
			msgWindow.focus();
			msgWindow.location.href = thisurl;
		}
		else {
*/			msgWindow=window.open(thisurl,'subwindow','toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,menubar=yes,resizable=yes,left=0,top=0');
//		}
	}


}

var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off)
var memoryduration="7" //persistence in # of days


/////No need to edit beyond here //////////////////////////

function getElementbyClass(rootobj, classname){
var temparray=new Array()
var inc=0
var rootlength=rootobj.length
for (i=0; i<rootlength; i++){
if (rootobj[i].className==classname)
temparray[inc++]=rootobj[i]
}
return temparray
}

function sweeptoggle(ec){
var inc=0
while (ccollect[inc]){
ccollect[inc].style.display=(ec=="contract")? "none" : ""
inc++
}
revivestatus()
}


function expandcontent(curobj, cid){
if (ccollect.length>0){
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="none")? "none" : ""
curobj.src=(document.getElementById(cid).style.display=="none")? expandsymbol : contractsymbol
}
}

function revivecontent(){
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="none"
}

function revivestatus(){
var inc=0
while (statecollect[inc]){
if (ccollect[inc].style.display=="none")
statecollect[inc].src=expandsymbol
else
statecollect[inc].src=contractsymbol
inc++
}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="none")
selectedItem+=ccollect[inc].id+"|"
inc++
}
if (get_cookie(window.location.pathname)!=selectedItem){ //only update cookie if current states differ from cookie's
var expireDate = new Date()
expireDate.setDate(expireDate.getDate()+parseInt(memoryduration))
document.cookie = window.location.pathname+"="+selectedItem+";path=/;expires=" + expireDate.toGMTString()
}
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
var alltags=document.all? document.all : document.getElementsByTagName("*")
ccollect=getElementbyClass(alltags, "switchcontent")
statecollect=getElementbyClass(alltags, "showstate")
if (enablepersist=="on" && get_cookie(window.location.pathname)!="" && ccollect.length>0)
revivecontent()
if (ccollect.length>0 && statecollect.length>0)
revivestatus()
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate


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;
  } }
}
function MM_swapImgRestore() { //v3.0
  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_swapImage() { //v3.0
  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 MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}