//Pop-up window
function popWin(theUrl,theName,theWidth,theHeight,theScrolling) {
	var opts=""		;
	if (theScrolling == 'auto') theScrolling = 'yes';
	opts="'left=50,top=50,screenX=50,screenY=50,width="+theWidth+",height="+theHeight+",menubar=no,location=no,resizable=yes,scrollbars="+theScrolling+",status=1'" ;
	PopUP=window.open(theUrl,theName,opts);
	PopUP.focus();
}

//Pop-up image
function popImg(theSrc,theName,theWidth,theHeight,theScrolling) {
	var opts=""		;
  var win ;
	if (theScrolling == 'auto') theScrolling = 'yes';
	opts="'left=50,top=50,screenX=50,screenY=50,width="+theWidth+",height="+theHeight+",menubar=no,location=no,resizable=yes,scrollbars="+theScrolling+",status=1'" ;
  win = window.open("",theName,opts) ;
  win.document.open() ;
  win.document.write('<html><head><title>Image</title></head>' +
    '<body><img src="' + theSrc + '"></body></html>') ;
  win.document.close() ;
}

// for use of i selection tools
var gW;
function showGuide(theClass,isStatic) {
	gW=window.open('/selectionguides/'+(isStatic?'tables/':'script/?db=')+theClass+(isStatic?'.html':''),'gW','left=100,top=50,screenX=100,screenY=50,width=780,height=500,menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=1');
	gW.focus();
}

// for use of pop-ups in MMS with selection tools in it
function popWinMMS(theNumber, isTable) {
	showGuide(theNumber, isTable);
}

function popWinMMSpopup(theURL) {
	popWin(theURL, 'mmspopup',100,50,'no');
}

var lW
function showParamSearch(theFAM) {
	lW=window.open('','lW','left=0,top=0,screenX=0,screenY=0,width=780,height=520,resizable,scrollbars');
	lW.location.href="http://stepsearch.semiconductors.philips.com/philips-ps/ss.asp?FAM="+theFAM;
	lW.focus();
}

// don't show i selection guide icon for NN6+
function printGuideIcon(line) {
	if (!browser.isNS6up) {
		document.write(line);
		document.close();
	}
}

_page.link["contact"]="http://www.semiconductors.philips.com/support/";
_page.link["support"]="/support/";

if(browser.isNS6x || browser.isNS7x){
	// Use div overflow for large tables for Netscape.
	document.write("<style>.hor_scroll{position:relative;width:550px;overflow:moz-scrollbars-horizontal;}</style>");
}

// set height of tabbed boxes according to content height
function setDivHeight(container,left,right) {
	sdh_command = 'setDivHeight("'+container+'","'+left+'","'+right+'")';
	if (gE(left) && gE(right)) {
		var divheightleft = gE(left).offsetHeight;
		var divheightright = gE(right).offsetHeight;
		var divheight = Math.max(divheightleft,divheightright);
		sH(gE(container),divheight);
		if (browser.isGecko) { 
			gE('p-news-container') ? gE('p-news-container').innerHTML = gE('p-news-container').innerHTML : 1;
			gE('p-apps-prod-container') ? gE('p-apps-prod-container').innerHTML = gE('p-apps-prod-container').innerHTML : 1;
		}
		if (_page.boxToFlip) {
			_page.flipTabs(_page.boxToFlip);
		}
	} else {
		setTimeout(sdh_command,10);
	}
}
//Called in page (Mozilla)
//setDivHeight("p-news-container","p-content-pressreleases","p-content-infocus");
//setDivHeight("p-apps-prod-container","p-content-applications","p-content-products");

_page.flipTabs = function (boxToFlip) {
	// This function will flip the default tab to show in the tabbed info box

	if (boxToFlip=='p-extrainfo-products') {
		hE(gE('p-content-applications'));sE(gE('p-content-products'));
		gE('products-applications').style.backgroundImage='URL(/general/images/tab_light.gif)';
		gE('products-products').style.backgroundImage='URL(/general/images/tab_dark.gif)';
	} else {
		return 1;
	}	
}

_page.searchHandler = function (searchform_id) {
	// This function will open the standard search application. This function can be overruled.
	var objSearch = "";
	var searchform_global = "searchform";
	var searchform_404 = "searchform_404";
	var searchform_404_old = "404";
	
	// Get search form element
	if(typeof(searchform_id)=="undefined" || searchform_id=="") {
		searchform_id = searchform_global;	
	}
	else if(searchform_id == searchform_404_old) {
		searchform_id = searchform_404;
	}	
	
	objSearch = gE(searchform_id);
	if(typeof(objSearch)!="undefined") {
		
		// Search form
		if(searchform_id == searchform_404) {
			var current_locale = _page.locale;
			var current_division = _page.area;
		
			// Set hidden field locale (L)
			if(typeof(document.forms[searchform_id].l)=="undefined") {
					var hideManual = false;
					var fld_locale = document.createElement("input");
					
					try { // Doesn't work on IE MAC 5x
						fld_locale.type = "hidden";
					} catch(e) {
						hideManual = true;
					}	
				
					fld_locale.id = "current_locale";
					fld_locale.name = "l";
					fld_locale.value= current_locale;
					objSearch.appendChild(fld_locale);
					
					if(hideManual == true) hE(gE("current_locale"));					
			} 
			else if(trim(document.forms[searchform_id].l.value) == ""){
				document.forms[searchform_id].l.value = current_locale;
			}
			
			// Set hidden field division (H)
			if(typeof(document.forms[searchform_id].h)=="undefined") {
					var hideManual = false;
					var fld_division = document.createElement("input");
					
					try { // Doesn't work on IE MAC 5x
						fld_division.type = "hidden";
					} catch(e) {
						hideManual = true;
					}
					
					fld_division.id = "current_division";
					fld_division.name = "h";
					fld_division.value= current_division;
					objSearch.appendChild(fld_division);
					
					if(hideManual == true) hE(gE("current_division"));
			}
			else if(trim(document.forms[searchform_id].h.value) == ""){
				document.forms[searchform_id].h.value = current_division;
			}
			
			// Replace name: searchtext - backwards compatibility
			if(typeof(document.forms[searchform_id].q)=="undefined") {
				var search_text = gE("search_text");
				if(search_text!= null) if(search_text.name!="q") search_text.name = "q";
			}	
			// Replace name: searchsection - backwards compatibility
			if(typeof(document.forms[searchform_id].s)=="undefined") {
				var search_section = gE("search_section");
				if(search_section!= null) if(search_section.name!="s") search_section.name = "s";
			}
		}
		
		// Set new form attributess
		objSearch.action = "http://www.search.philips.com/search/search";
		objSearch.method = "GET"
		objSearch.acceptCharset = "UTF-8";

		// Use Inquiro for Semi queries if useInquiro = 1;
		var useInquiro = 0;
		if ((document.forms[searchform_id].s.value=='semi') && (useInquiro==1)) {
			var hideManual = false;
			var inquiro_fld = document.createElement("input");

			try { // Doesn't work on IE MAC 5x
				inquiro_fld.type = "hidden";
			} catch(e) {
				hideManual = true;
			}

			inquiro_fld.id = "inquiro_query";
			inquiro_fld.name = "query";
			inquiro_fld.value = document.forms[searchform_id].q.value;
			objSearch.appendChild(inquiro_fld);

			if(hideManual == true) hE(gE("inquiro_query"));
			
			objSearch.action = "http://www.semiconductors.philips.com/cgi-bin/Inquiro/Search.pl";
		}
		
		// Submit form
		objSearch.submit();
	}
	
	// Cancel onclick/submit event
	return false;
}   



// ------------------------------- SURVEY FUNCTIONS -------------------------------------

function getCookie(Name) {
	var search = Name + "="
	if (top.document.cookie.length > 0) { // if there are any cookies
		offset = top.document.cookie.indexOf(search) 
		if (offset != -1) { // if cookie exists 
			offset += search.length 
			// set index of beginning of value
			end = top.document.cookie.indexOf(";", offset) 
			// set index of end of cookie value
			if (end == -1) 
				end = top.document.cookie.length
			return unescape(top.document.cookie.substring(offset, end))
		} 
	}
	return null;
}

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
		top.document.cookie = curCookie;
}

function setLongCookie (name, value, path, domain, secure) {
		var exp = new Date();
		var afterAlongWhile = exp.getTime() + (5*365*24*60*60*1000);
		exp.setTime(afterAlongWhile);
		setCookie(name, value, exp,path,domain, secure);
}

function expireCookie (name, value, path, domain, secure) {
		var exp = new Date();
		var longAgo = exp.getTime() - (365*24*60*60*1000);
		exp.setTime(longAgo);
		setCookie(name, value, exp,path,domain, secure);
}

function cookiesEnabled () {
			//test if cookies are enabled....	
			var theDate = new Date().toGMTString();
			setCookie ("cookietest", theDate);
			return getCookie("cookietest") == theDate;
}

// ------------------------------- TAXONOMY FUNCTIONS -------------------------------------

function loadExternalScript(file) {
	// includes an external javascript within a javascript
	var command = "loadExternalScript('" + file + "')";
	if (gE('p-footertable')) {
		var extScript  = document.createElement("script");
		extScript.type = "text/javascript";
		extScript.src  = file;
		document.body.appendChild(extScript);
	} else {
		loadTimer = setTimeout(command,50);
	}
}

var taxLanguage = (_page.locale == "cn_zh") ? "scn" : (_page.locale == "tw_zh") ? "tcn" : (_page.locale == "jp_ja") ? "jp" : "en";
loadExternalScript("/javascript/" + taxLanguage + "/taxonomy.js");

// ------------------------------- END OF TAXONOMY FUNCTIONS -------------------------------------


// ------------------------------- SURVEY FUNCTIONS -------------------------------------

function showSurvey() {
	if (cookiesEnabled) {		
		if ((getCookie("homepage_survey") != 'yes') && (location.hostname.indexOf("download")==-1) && (/^\/(index\.html)*$/.test(location.pathname)==1)) {
			var expires = new Date();
			expires.setFullYear(expires.getFullYear()+1);
			thePopUPWindow=window.open('/survey/homepage_poll/','thePopUPWindow','left=100,top=50,screenX=100,screenY=50,width=800,height=680,menubar=no,location=no,resizable=yes,scrollbars=yes,status=1');
			if (thePopUPWindow) { thePopUPWindow.focus(); }
			setCookie('homepage_survey', 'yes', expires, '/', '192.168.0.157');
			setCookie('homepage_survey', 'yes', expires, '/', 'semiconductors.philips.com');
			setCookie('homepage_survey', 'yes', expires, '/', 'semiconductors.com');
		} else {
			//expireCookie("homepage_survey");
		}
	}
}
showSurvey();

//	if (cookiesEnabled) {
//		if ((getCookie("200411survey") != 'yes') && (location.hostname.indexOf("download")==-1)) {
//			thePopUPWindow=window.open('/survey/nov04/','thePopUPWindow','left=100,top=50,screenX=100,screenY=50,width=800,height=500,menubar=no,location=no,resizable=yes,scrollbars=yes,status=1');
//			thePopUPWindow.focus();
//		} else {
//			//expireCookie("200411survey");
//		}
//	}


//	if (cookiesEnabled()) {
//		if ((getCookie("survey16seen") != 'yes') && (/\/survey\//.test(location.pathname)!=1)) {
//			thePopUPWindow=window.open('/survey/july2005/','thePopUPWindow','left=100,top=50,screenX=100,screenY=50,width=800,height=500,menubar=no,location=no,resizable=yes,scrollbars=yes,status=1');
//			thePopUPWindow.focus();
//		}
//	}


// ------------------------------- END OF SURVEY FUNCTIONS -------------------------------------
