	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_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_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_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 changeLangId() {
 		document.changelang.action = 'langchange.jsp';
 		document.changelang.pat.value = window.location.href;
 		document.changelang.langid.value = 'id';
		document.changelang.submit();
	}
	
	 function changeLangEn() {
 		document.changelang.action = 'langchange.jsp';
 		document.changelang.pat.value = window.location.href;
 		document.changelang.langid.value = 'en';
		document.changelang.submit();
	}
	 
	function changeProfile() {
	 		document.changeProf.action = 'sign_profile_update.jsp';
			document.changeProf.submit();
	}
	
	function changeTab(tabid) {
 		document.tabform.action = 'tabchange.jsp';
 		document.tabform.pat.value = window.location.href;
 		document.tabform.tab.value = tabid;
		document.tabform.submit();
	}
	
	function loginform(){
		document.formlogin.action='login.jsp';
		document.formlogin.burl.value=window.location.href;
		document.formlogin.login.value='1';
		document.formlogin.submit();
	}
	
	function registerform(){
		var des = 'http://203.78.116.55';
		document.forms[1].action=des+'/spn/nts/web/login.jsp';
		document.forms[1].burl.value=window.location.href;
		document.forms[1].login.value='1';
		document.forms[1].submit();
	}
	
		function logoutform(){
		var des = 'http://localhost:8080';
		var src =  'http://localhost:8080';
		document.forms[1].action=des+'logout.jsp';
		document.forms[1].tgtPg.value=src+'/web/store_index.jsp?site=4&logout=1';
		document.forms[1].errPg.value=src+'/web';
		document.forms[1].logout.value='1';
		document.forms[1].submit();
	}
	
	function find(obj){
		var brandIdValue = 0;
		for( var i =0; i < obj.length; i++)
		{
			if(obj[i].selected==true)
			{
				brandIdValue=obj[i].value;				
				return brandIdValue;
			}
		}
		return null;
	}
	
	function doChecking(){
		
		if(find(objA)!= -1 && find(objB) != -1)
		{
			document.all.namedItem("purchase_div").style.visibility="visible"; 
			//alert("open please");
		}
		else
		{
			document.all.namedItem("purchase_div").style.visibility="hidden"; 
			//alert("close");
		}		
	}
	
	function doSelect()	{
		doChecking();
	}
	
	function doPreview(urls){
		var bImage = false;
		if(urls.search('.gif$') != -1)bImage = true;
		else if(urls.search('.bmp$') != -1)bImage = true;
		else if(urls.search('.png$') != -1)bImage = true;
		else if(urls.search('.jpg$') != -1)bImage = true;
		else if(urls.search('.jpeg$') != -1)bImage = true;
		else if(urls.search('.wma$') != -1 )
		{				
			var bWin = window.open('',null,
   			 "width=300px,height=45px,status=yes,toolbar=no,scrollbars=no,menubar=no,location=no,resizable=no");
			callControl(bWin,urls,300,45);
			return;	
		}
		else if(urls.search('.wmv$') != -1 )
		{
			var bWin = window.open('',null,
   		 	"width=316px,height=300px,status=yes,toolbar=no,scrollbars=no,menubar=no,location=no,resizable=no");
			callControl(bWin,urls,316,300);
			return;	
		}else if(urls.search('.mid$') != -1 )
		{
			var bWin = window.open('',null,
   		 	"width=316px,height=300px,status=yes,toolbar=no,scrollbars=no,menubar=no,location=no,resizable=no");
			callControl(bWin,urls,316,300);
			return;	
		}else if(urls.search('.wav$') != -1 )
		{
			var bWin = window.open('',null,
   		 	"width=316px,height=300px,status=yes,toolbar=no,scrollbars=no,menubar=no,location=no,resizable=no");
			callControl(bWin,urls,316,300);
			return;	
		}			
		else bImage = false;
			
		if(!bImage)
		{
			var bWin = window.open(urls,null,
   			 "width=300px,height=200px,status=yes,toolbar=no,scrollbars=no,menubar=no,location=no,resizable=no");
			//callControl(bWin,urls);
		}
		else	
			callPop(urls,"preview");
	}
	

	function callControl(bWin,urls,wh,hh){
		bWin.document.write(
		'<html>\n'+
		'<head>\n'+
		'<title>Web Portal Content Preview</title>\n'+
		'<meta content="no-cache" http-equiv="pragma"/>\n'+
		'<meta content="no-cache" http-equiv="cache-control"/>\n'+
		'</head>\n'+
		'<script type="text\/javascript">\n'+
		'function resizeWind()\n'+
		'{\n'+
		'var objEmb = document.all.namedItem("kontent");\n'+
		'var newHeight = objEmb.height;alert("height: + newHeight");\n'+
		'var newWidth = objEmb.width;alert("width: + newWidth");\n'+
		'window.resizeTo(newWidth,newHeight);\n'+
		'}<\/script>\n'+	
		'<body bgcolor="#ffffff" leftmargin="0" topmargin="0" >\n'+
		'<table width="100%" height="100%" cellspacing="1" cellpadding="1" border="0" bgcolor="#ffffff">\n'+
		'<tr>\n'+
		'<td>\n'+
		'<embed width="'+wh+'" height="' +hh+'" id="kontent" scale="tofit" controls="true" autostart="true" src="'+ urls +'" onload=""/>\n'+
		'</td>\n'+
		'</tr>\n'+
		'</table>\n'+
		'</body>\n'+
		'</html>');
	}
	
	
	function callPop(imageURL,imageTitle){
		PosX = 10;
		PosY = 10;
		defWidth  = 600;
		defHeight = 400;
		var imgw = window.open('','_blank','scrollbars=no,resizable=no,width='+defWidth+',height='+defHeight+',left='+PosX+',top='+PosY);
		if( !imgw ) 
		{ alert('Please deactivate your browser popup blocker to see this preview. \n'+
				'Silahkan non aktifkan popup blocker browser anda untuk melihat preview.');
			return true; } //popup blocker will be okay
		imgw.document.write('<html><head><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
		'function resizeWin() {\n'+
		'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
		'var oH = document.images[0].height, oW = document.images[0].width;\n'+
		'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
		'window.doneAlready = true;\n'+ //for Safari and Opera
		'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
		'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n'+
		'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }\n'+
		'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
		'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
		'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
		'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
		'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
		'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
		'if( !window.opera ) { x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); }\n'+
		'/*add for visibility*/document.all.namedItem("emb").hidden=false;}\n'+
		'<\/script>'+
		'<\/head><body onload="resizeWin();">'+
		(document.layers?('<layer left="0" top="0">'):('<div style="position:absolute;left:0px;top:0px;display:table;">'))+
		'<embed id="emb" hidden=true style="height:0;visibility:false"><img style="visibility:false" src="'+imageURL+'" alt="Loading image ... \nUnduh gambar" title="" onload="resizeWin();"><\/embed>'+
		(document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
		imgw.document.close();
		if( imgw.focus ) { imgw.focus(); }
		return false;
	}



function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}


function isDate(dtStr){
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function ValidateForm(){
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }

function textCounter(field, countfield, maxlimit) 
{
	if (field.value.length > maxlimit) 
	field.value = field.value.substring(0, maxlimit);
	else 
	countfield.value = maxlimit - field.value.length;
}

function checkvalue() {
	subject = document.forms['formisi'].subject.value;		
	message	= document.forms['formisi'].message.value;		
	if ((subject == null) || (subject == "")) {
		// something is wrong
		alert('Input Subjek Belum Terisi');
		return false;
	}	
	else if ((message == null) || (message=="")) {
		// something else is wrong
		alert('Input Message Belum Terisi');
		return false;
	}	
	return true;
}

