/*	Objective : Function for popup
Date : 21Jun2005	Author : Jason
Date : 24Jun2005	Updated by Harkirti
Date : 21Mar2006	Modifed the MyWindow function for artf273769*/

var enablepersist="off" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)





function NewWindow(mypage,myname,w,h,scroll,resize){
	if(scroll == 1){
		scroll= 'yes';
	}
	else{
		scroll= 'no';
	}
	if(resize == 1){
		resize= 'yes';
	}
	else{
		resize= 'no';
	}
	if (w=='null' || w=='')
	{
		w=425;
	}
	if (h=='null' || h=='')
	{
		h=425;
	}
	var winl = 150;
	var wint = 180;
	var vloc = 'no';
	var vtool = 'no';
	var vdire = 'no';
	var vstatus = 'yes';
	var settings ='height='+h+',';
		settings +='width='+w+',';
		settings +='top='+wint+',';
		settings +='left='+winl+',';
		settings +='scrollbars='+scroll+',';
		settings +='resizable='+resize+',';
		settings +='toolbar= '+vtool+',';
		settings +='location= '+vloc+',';
		settings +='directories= '+vdire+',';
		settings +='status= '+vstatus+',';

		win=window.open(mypage,myname,settings);

	}


function NewWindowWithoutStatusBar(mypage,myname,w,h,scroll,resize){
	if(scroll == 1){
		scroll= 'yes';
	}
	else{
		scroll= 'no';
	}
	if(resize == 1){
		resize= 'yes';
	}
	else{
		resize= 'no';
	}
	if (w=='')
	{
		w=425;
	}
	if (h=='')
	{
		h==425;
	}
	var winl = 150;
	var wint = 180;
	var vloc = 'no';
	var vtool = 'no';
	var vdire = 'no';
	var vstatus = 'yes';
	var settings ='height='+h+',';
		settings +='width='+w+',';
		settings +='top='+wint+',';
		settings +='left='+winl+',';
		settings +='scrollbars='+scroll+',';
		settings +='resizable='+resize+',';
		settings +='toolbar= '+vtool+',';
		settings +='location= '+vloc+',';
		settings +='directories= '+vdire+',';
		settings +='status=no';

		win=window.open(mypage,myname,settings);

	}


function NewStandardWindow(mypage,myname,settings){
		win=window.open(mypage,myname,settings);
}
/* Function to display messg on the new popup window
   Updated By: Ganeshan
*/

function MyWindow(mypage,myname,w,h,scroll,resize,mesg){
	if(scroll == 1){
		scroll= 'yes';
	}
	else{
		scroll= 'no';
	}
	if(resize == 1){
		resize= 'yes';
	}
	else{
		resize= 'no';
	}
	if (w=='')
	{
		w=425;
	}
	if (h=='')
	{
		h==425;
	}
	var winl = 150;
	var wint = 180;
	var vloc = 'no';
	var vtool = 'no';
	var vdire = 'no';
	var vstatus = 'yes';
	var settings ='height='+h+',';
		settings +='width='+w+',';
		settings +='top='+wint+',';
		settings +='left='+winl+',';
		settings +='scrollbars='+scroll+',';
		settings +='resizable='+resize+',';
		settings +='toolbar= '+vtool+',';
		settings +='location= '+vloc+',';
		settings +='directories= '+vdire+',';
		settings +='status= '+vstatus+',';

		// Change Begin for artf273769
		win=window.open('',myname,settings);
		win.document.open('text/html; charset=UTF-8');
		win.document.write('<HTML><HEAD>');
		win.document.write('<link rel="stylesheet" type="text/css" href="/consumer/hm/styles/style.css"/>');
		win.document.write('<META http-equiv="Content-Type" content="text/html; charset=UTF-8">');
		win.document.write('</HEAD><BODY>');
		win.document.write('<p class="comparePhonePop">'+mesg+'</p>');
		win.document.writeln('</BODY></HTML>');
		win.document.close();
		// Change End for artf273769

	}



function switchImg(firstimage,firstsrc){
  if (document.images) {
    document.images[firstimage].src = firstsrc;
  }
}

function OnChangeList(index)
{
	if (index==1)
	{
		var index=document.Downloads.phonesel1.options.selectedIndex;
		document.Downloads.phonesel2.options[index].selected=true;

	}else{
		var index=document.Downloads.phonesel2.options.selectedIndex;
		document.Downloads.phonesel1.options[index].selected=true;
	}
}


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 thestate=(ec=="expand")? "block" : "none"
	var inc=0
	while (ccollect[inc]){
		ccollect[inc].style.display=thestate
		inc++
	}
	revivestatus()
}

function contractcontent(omit){
	var inc=0
	while (ccollect[inc]){
		if (ccollect[inc].id!=omit)
			ccollect[inc].style.display="none"
		inc++
	}
}


function revivecontent(){
	contractcontent("omitnothing")
	selectedItem=getselectedItem()
	selectedComponents=selectedItem.split("|")
	for (i=0; i<selectedComponents.length-1; i++)
		document.getElementById(selectedComponents[i]).style.display="block"
}

function revivestatus(){
	var inc=0
	while (statecollect[inc]){
		if (ccollect[inc].style.display=="block")
			statecollect[inc].innerHTML=contractsymbol
		else
			statecollect[inc].innerHTML=expandsymbol
		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=="block")
			selectedItem+=ccollect[inc].id+"|"
		inc++
	}

	document.cookie=window.location.pathname+"="+selectedItem
}

/*
 * This JavaScript function takes one parameter, which is the string that needs to be
 * trimmed. The function then loops through each of the characters of this string,
 * starting with the first one. If the current character in the loop is a single white
 * space " ", the function removes it from the string and continues with the loop. The
 * loop goes on until it finds character, which is different than a single white space
 * or until it reaches the end of the string. After the function exits the loop, it
 * returns the trimmed string.
 */
function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
return sString;
}

function getImagePath(className,name,width,height,alt,contextRoot,imagePath)

        {

          var imageTag = "";

                          imageTag = "<img ";

                          if(className != '')

                                      imageTag += " class ='" +  className + "' ";

                          if(name != '')

                                      imageTag += " name ='" +  name + "' ";

                          if(width != '')

                                      imageTag += " width ='" +  width + "' ";

                          if(height != '')

                                      imageTag += " height ='" +  height + "' ";

                          if(alt != '')

                                    {

                                      imageTag += " alt ='" +  alt + "' ";

                                      imageTag += " title ='" +  alt + "' ";

                                    }



          imageTag += " src ='" + contextRoot + imagePath + "'></img>";

          return (imageTag);

        }


/* This function is called by Flash Promo which are displayed on the Hellomoto Site */
function OpenLink()
{
	if(hyperlink=='')
		return;
	if(winStyle=='0')
	{
		window.location.href=hyperlink;
	}
	else if(winStyle=='1')
	{
		window.open(hyperlink,'Hellomoto','');
	}
	else
	{
		NewWindow(hyperlink,'Hellomoto',popW,popH,popS,popR);
	}

}
function OpenLink(pNum)
{
	if( !("hasMultipleHyperlink" in window))
	{
			if(hyperlink=='')
				return;
			if(winStyle=='0')
			{
				window.location.href=hyperlink;
			}
			else if(winStyle=='1')
			{
				window.open(hyperlink,'Hellomoto','');
			}
			else
			{
				NewWindow(hyperlink,'Hellomoto',popW,popH,popS,popR);
			}
	}
	else if( hasMultipleHyperlink  != true)
	{
			if(hyperlink=='')
				return;
			if(winStyle=='0')
			{
				window.location.href=hyperlink;
			}
			else if(winStyle=='1')
			{
				window.open(hyperlink,'Hellomoto','');
			}
			else
			{
				NewWindow(hyperlink,'Hellomoto',popW,popH,popS,popR);
			}
	}
	else
	{
			if(hyperlinks[pNum]==null)
				return;
			if(win_Style[pNum]=='0')
			{
				window.location.href=hyperlinks[pNum];
			}
			else if(win_Style[pNum]=='1')
			{
				window.open(hyperlinks[pNum],'Hellomoto','');
			}
			else
			{
				NewWindow(hyperlinks[pNum],'Hellomoto',popUp_Width[pNum],popUp_Height[pNum],popUp_Resize[pNum],popUp_Scroll[pNum]);
			}
	}
}

function openNHPLink(hyperlink,windowStyle,popH,popR,popS,popW)
{
			if(hyperlink=='')
				return;
			if(windowStyle=='0')
			{
				window.location.href=hyperlink;
			}
			else if(windowStyle=='1')
			{
				window.open(hyperlink,'Hellomoto','');
			}
			else
			{
				NewWindow(hyperlink,'Hellomoto',popW,popH,popS,popR);
			}
			if(isWebTrendsEnabled == '1')
				dcsMultiTrack('DCS.dcsuri',hyperlink,'WT.ti',webTrendsTag,'DCSext.SpecialPromo',promoName);
}

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" && ccollect.length>0){
		document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0"
		firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
		if (!firsttimeload)
			revivecontent()
	}
	if (ccollect.length>0 && statecollect.length>0)
		revivestatus()
}

function DoNav(theUrl)
{
        document.location.href = theUrl;
}

/* This function is called by all Site and Primary Navigations on the Hellomoto Site
   to generate the requisite URLS for hyperlinks as per input parameters*/
function navigateByWidowStyle(hyperlink, windowStyle, popW ,popH ,popR ,popS)
 {
 	if(popW == null || popW == '') popW="425";
 	if(popH == null || popH == '') popH="425";
 	if(popS == null) popS="";
 	if(popR == null) popR="";
 	var outputURL = '';
 	if (windowStyle != null)
 	{
 		if (windowStyle == '2')
 		{
			//if window style is Popup,the java script function NewWindow
			// is used to open a popup.
			NewWindow( hyperlink ,'Hellomoto',popW ,popH ,popS ,popR);
 		}
 		else if (windowStyle == '1')
 		{
			//if window style is New window,the URL is opened in a new window.
			window.open(hyperlink);
 		}
 		else
 		{
			//if window style is Same window,the URL is opened in same window.
			window.location.href = hyperlink;
 		}
 	}

}

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
