/*
	Copyright Infinite Solutions Co.,Ltd 2009;
	index.php v 2.0 2009.05.26;
	Infinite Solutions JS Main File
*/
function toconvert(otoutf,oelement)
{
	var sourceareastr = oelement.value;
	var strlen = sourceareastr.length;
	var str="";
	if (otoutf=='wintoutf') { 
		 for (i = 0; i < strlen;  i++) { 
		  	var codestr = sourceareastr.charCodeAt(i);
		   	switch(codestr) {
				case 184: codestr=1105;break; 
				case 168: codestr=1025;break; 
			
				case 175: codestr=1198; break; 
				case 191: codestr=1199; break; 
				
				case 170: codestr=1256; break; 
				case 186: codestr=1257; break; 
		   }
		   if (256>codestr && codestr>191) 
		   		codestr=codestr+848;
		   switch(codestr) {
				case 1111: codestr=1199;break;   
				case 1031: codestr= 1198; break; 
				
				case 1108: codestr=1257; break; 
				case 1028: codestr=1256; break; 
		   }
			   str=str+String.fromCharCode(codestr);
		} 
		
		oelement.value=str;	   	   
	 
	} 
	else 
		if (otoutf=='utftowin') { 
			   for (i = 0; i < strlen;  i++) { 
					var codestr = sourceareastr.charCodeAt(i);
					switch(codestr) {
						case 1025: codestr=168;break; 
						case 1105: codestr=184;break; 
							
						case 1198: codestr=175; break; 
						case 1199: codestr=191; break; 
						
						case 1256: codestr=170; break; 
						case 1257: codestr=186; break; 
						
						case 415: codestr=170; break; 
						case 629: codestr=186; break; 
					}
					if (1280>codestr && codestr>1023) 
							codestr=codestr-848; 
					str=str+String.fromCharCode(codestr);
		   		}
	   			
				oelement.value=str;
	
	   		
        }
		
}

var editorMY=[];

function checkFormConvert(oCheckformId)
{
	var formError=0;
	var Checkform=document.getElementById(oCheckformId);
	var oldElemen;
	if(Checkform)
	{
		inputInd=0;		
		while(Checkform.getElementsByTagName('input')[inputInd])
		{
			
			var testinput=Checkform.getElementsByTagName('input')[inputInd];
			if(testinput.type!='file'){
				toconvert('wintoutf',testinput);
			}	
				
				if (testinput.className.indexOf("im_extvalidEmail")!=-1 ) {
					if(!validateEmail(testinput.id)){
						formError++;
					}
				}
				else
					if (testinput.className.indexOf("im_extvalidREEmail")!=-1 || testinput.className.indexOf("im_extvalidREpass")!=-1 ) {
						if(oldElemen && oldElemen.value!=testinput.value || testinput.value==''){
							if (testinput.className.indexOf("im_extvalidREEmail")!=-1)
								validateInputRE(testinput.id,"im_extvalidREEmail");
							else
								validateInputRE(testinput.id,"im_extvalidREpass");
							formError++;
						}
					}
					else
						if (testinput.className.indexOf("im_extvalid")!=-1 ) {
							if(!validateInput(testinput.id)){
								formError++;						
							}
						}
				
				oldElemen=testinput;
			
			inputInd++;
		}
		
		textareaInd=0;
		while(Checkform.getElementsByTagName('textarea')[textareaInd])
		{			
			var testarea=Checkform.getElementsByTagName('textarea')[textareaInd];						
			toconvert('wintoutf',testarea);	
			
			if (testarea.className.indexOf("im_extvalid")!=-1 ) {
				if(!validateInput(testarea.id)){
					formError++;						
				}
			}
			if(editorMY && editorMY[testarea.id])
				editorMY[testarea.id].loadContentFromField();
			textareaInd++;
		}		
	}
	//alert(formError);
	if(formError==0)
		return true;
	else	
		return false;
}



	function removescript(oelement){
		
		var fcontainer=document.getElementById(oelement);
		jsind=0;
		var mainbody=document.getElementsByTagName('body')[0];
		while(fcontainer.getElementsByTagName('script')[jsind]){
			var oldscript=fcontainer.getElementsByTagName('script')[jsind];
			if(document.getElementById(oelement+'_'+jsind)){
				var removejs=document.getElementById(oelement+'_'+jsind)
				mainbody.removeChild(removejs);
			}
			jsind++;
		}
		
	}

	function loadscript(oelement){
		
		var fcontainer=document.getElementById(oelement);
		jsind=0;
		var mainbody=document.getElementsByTagName('body')[0];
		while(fcontainer.getElementsByTagName('script')[jsind]){
			var oldscript=fcontainer.getElementsByTagName('script')[jsind];
			
			var newscript=document.createElement('scr'+'ipt');
			newscript.text=oldscript.text;
			newscript.id=oelement+'_'+jsind;
			newscript.type="text/javascript";
			if(oldscript.src)
				newscript.src=oldscript.src;
			
	
			mainbody.appendChild(newscript);
			
			jsind++;
			
		}
		
	}


	var winW = 800, winH = 600, winOrgW=800, WinOrgH=600, sizeload='no';
	
	function winodowsize(){		
		if (parseInt(navigator.appVersion)>3) 
		{
			 if (navigator.appName=="Netscape") 
			 {
				  winW = window.innerWidth;					 
				  winH = window.innerHeight;
			 }
			else
			 if (navigator.appName.indexOf("Microsoft")!=-1 ) 
			 {
				  winW = document.body.offsetWidth;					  
				  winH = document.body.offsetHeight;
			 }
			else
			 if(window.XMLHttpRequest)
			 {
				if(document.body.offsetHeight)
				 winH = document.body.offsetHeight;
				if(window.innerWidth)
				 winW = window.innerWidth;
			 }
			 
			 if(sizeload=='no'){
				 sizeload='yes';
				 winOrgW=winW;
				 winOrgH=winH;
  			     
				 if(document.getElementById('filebodyTDmainIndex') && winW<1120  && document.getElementById('myLangTD')){
					document.getElementById('filebodyTDmainIndex').style.width='1100px';
				 }
				 else{
					 mDw=winW-20; 
					 if(document.getElementById('filebodyTDmainIndex') && document.getElementById('myLangTD'))
					 document.getElementById('filebodyTDmainIndex').style.width=mDw+'px';
				 }
			 }
		
			
			 if(document.getElementById('sotester2')){
				document.getElementById('sotester2').setAttribute("width",winW);
				document.getElementById('sotester2').setAttribute("height",winH);
			 }
		}
	}


	/******* Alert MSG START 2009-05-19 ***********/
	
	function alertshow(otit,otext){	
		window.scrollTo(0,0);
		if (parseInt(navigator.appVersion)>3) 
		{
			 if (navigator.appName=="Netscape") 
			 {
				  winW = window.innerWidth;					 
				  winH = window.innerHeight;
			 }
			else
			 if (navigator.appName.indexOf("Microsoft")!=-1 ) 
			 {
				  winW = document.body.offsetWidth;					  
				  winH = document.body.offsetHeight;
			 }
			else
			 if(window.XMLHttpRequest)
			 {
				if(document.body.offsetHeight)
				 winH = document.body.offsetHeight;
				if(window.innerWidth)
				 winW = window.innerWidth;
			 }
			 			 			 
		}
	
		newPosX=(winW-600)/2;
		newPosY=200;
		if(document.getElementById('ext-comp-MSG1002')){
			
			if(document.getElementById('ext-genMSG57') && otit!=''){
				document.getElementById('ext-genMSG57').innerHTML=otit;
			}
			if(document.getElementById('ext-genMSG68') && otext!=''){
				document.getElementById('ext-genMSG68').innerHTML=otext;
			}
			if(document.getElementById('ext-genMSG56')){
				document.getElementById('ext-genMSG56').setAttribute("width",winW);
				document.getElementById('ext-genMSG56').setAttribute("height",winH);	
				document.getElementById('ext-genMSG56').style.display='block';
			}
			
			
			document.getElementById('ext-comp-MSG1002').style.top=newPosY+'px';
			document.getElementById('ext-comp-MSG1002').style.left=newPosX+'px';
			document.getElementById('ext-comp-MSG1002').style.visibility='visible';
			
		}
	}
	
	function alertclose(){
		if(document.getElementById('ext-comp-MSG1002')){			
			document.getElementById('ext-comp-MSG1002').style.top='-1000px';
			document.getElementById('ext-comp-MSG1002').style.left='-1000px';
			document.getElementById('ext-comp-MSG1002').style.visibility='hidden';
			document.getElementById('ext-genMSG56').style.display='none';
		}	
	}
	
	
	function alertchange(otype){
		
		if(otype=='alert'){
			if(document.getElementById('ext-genMSGOK21')){		
				document.getElementById('ext-genMSGOK21').className='x-panel-btn-td';
				document.getElementById('ext-genMSGCANCEL45').className='x-panel-btn-td x-hide-offsets';
				document.getElementById('ext-genMSGlogo').className='ext-mb-fix-cursor';
			}	
		}
		else
			if(otype=='window'){
				if(document.getElementById('ext-genMSGOK21')){		
					document.getElementById('ext-genMSGOK21').className='x-panel-btn-td x-hide-offsets';
					document.getElementById('ext-genMSGCANCEL45').className='x-panel-btn-td';
					document.getElementById('ext-genMSGlogo').className='';
				}
			}						
	}


	/******* Alert MSG END ***********/	
	
	function papertree(otype,oid){
		
		if(otype=='plus'){
			document.getElementById(oid+'_p').style.display='block';
			document.getElementById(oid+'_m').style.display='none';
			document.getElementById(oid+'_table').style.display='none';
		}
		else{
			document.getElementById(oid+'_p').style.display='none';
			document.getElementById(oid+'_m').style.display='block';
			document.getElementById(oid+'_table').style.display='block';
		}
			
	}
	
	function infopriceDelete(oval,oele){
		Ext.MessageBox.confirm('Delete message', 'are you sure you wish to delete this message?', function(btn) {
                                      
			if (btn == 'yes') 
			{
				maskForm = new Ext.LoadMask(Ext.getBody(), {
					 msg: "loading ..."
				});
				maskForm.show();
				  Ext.Ajax.request({
							url: vsubpath+'/ismedia/advertise_save.php',
							method : 'POST',
							params : oval,
							failure: function() 
							{
								maskForm.hide();
							}, 
							success: function(fp, o)
							{
								maskForm.hide();
								
									// msg(o.result.success, o.result.msg);	
									if(document.getElementById(oele))
										document.getElementById(oele).innerHTML='';							
								  		
							}
					}); 
				
			}
		})
	}
	
	
	function getCookie(c_name)
	{
		if (document.cookie.length>0)
		  {
		  c_start=document.cookie.indexOf(c_name + "=");
		  if (c_start!=-1)
			{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
			}
		  }
		return "";
	}
	
	function setCookie(c_name,value,expiredays)
	{
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	}
	
	var oldsel=[];	
	var lenchcolor1=[];
	var lenchcolor2=[];
	var lenchcolor3=[];
	
	
	lenchcolor1['mmenumain_']='mmenu_itemon';
	lenchcolor2['mmenumain_']='mmenu_itemoff';
	lenchcolor3['mmenumain_']='mmenu_itemon';
	oldsel['mmenumain_']=0;
	
	lenchcolor1['subscrip_']='lencheckClass1';
	lenchcolor2['subscrip_']='lencheckClass2';
	lenchcolor3['subscrip_']='lencheckClass3';
	oldsel['subscrip_']=0;
	
	lenchcolor1['subscrip2_']='lencheckClass2_1';
	lenchcolor2['subscrip2_']='lencheckClass2_2';
	lenchcolor3['subscrip2_']='lencheckClass2_3';
	oldsel['subscrip2_']=0;
	
	lenchcolor1['dmenutop_']='tmenu_itemoff';
	lenchcolor2['dmenutop_']='tmenu_itemon';
	lenchcolor3['dmenutop_']='tmenu_itemoff';
	oldsel['dmenutop_']=0;
	
	lenchcolor1['dmenutopsub_']='tmenu1_itemoff';
	lenchcolor2['dmenutopsub_']='tmenu1_itemon';
	lenchcolor3['dmenutopsub_']='tmenu1_itemoff';
	oldsel['dmenutopsub_']=0;
	
	
	lenchcolor1['dhome_']='im_homepaperOff';
	lenchcolor2['dhome_']='im_homepaper';
	lenchcolor3['dhome_']='im_homepaperOff';
	oldsel['dhome_']=0;
	
	lenchcolor1['ext-comp-1002__vAdTab_']='x-tab-strip-active';
	lenchcolor2['ext-comp-1002__vAdTab_']='';
	lenchcolor3['ext-comp-1002__vAdTab_']='x-tab-strip-active';
	oldsel['ext-comp-1002__vAdTab_']='';
	
	lenchcolor1['ext-comp-1032__vAdTab_']='x-tab-strip-active';
	lenchcolor2['ext-comp-1032__vAdTab_']='';
	lenchcolor3['ext-comp-1032__vAdTab_']='x-tab-strip-active';
	oldsel['ext-comp-1032__vAdTab_']='';
	
	function reqLenFunc(otype,oele,oid,ocode){
		
		if(!oele.id){
			oele=document.getElementById(oele);
		}
		
		var jsTRid;
		jsTRid=ocode+oldsel[ocode];
		if(otype=='over' && oele.id!=jsTRid){
				oele.className=lenchcolor1[ocode];
		}
		
		if(otype=='out' && oele.id!=jsTRid){
				oele.className=lenchcolor2[ocode];
		}
		
		if(otype=='click' && oele.id!=jsTRid){
			
			var jsCHECKid;
			jsCHECKid='vlensel'+oldsel[ocode];
			if(oldsel[ocode]!=0){
				//alert(otype+','+oele+','+oid+','+ocode);
				if(document.getElementById(jsTRid))
					document.getElementById(jsTRid).className=lenchcolor2[ocode];
				if(document.getElementById(jsCHECKid))
					document.getElementById(jsCHECKid).checked='';
			}
			var jsCHECKid2;
			//alert(oldsel[ocode]);
			jsCHECKid2='vlensel'+oid;
			oldsel[ocode]=oid;
			setCookie(ocode,oid,1);
			
			oele.className=lenchcolor3[ocode];
			if(document.getElementById(jsCHECKid2))
				document.getElementById(jsCHECKid2).checked='checked';
		}
		
	}
	
	var oldTopMenuSel=0;
	function leftNewsMenuClick(oclick){
		
		if(document.getElementById('MenuHLeftMedia_li_'+oldTopMenuSel+'_sub')){
			document.getElementById('MenuHLeftMedia_li_'+oldTopMenuSel+'_sub').className='my_MenuHLeftMedia_item1_sub1';
		}
		
		if(document.getElementById('MenuHLeftMedia_li_'+oclick+'_sub')){
			document.getElementById('MenuHLeftMedia_li_'+oclick+'_sub').className='my_MenuHLeftMedia_item1_sub1-sel';
		}
		oldTopMenuSel=oclick;
	}
	
	function adcheckFunc(onumber){
		var res=document.getElementById('vadval').value;
		var tot=document.getElementById('vadtot').value;
		
		
		if(document.getElementById('vadsel'+onumber).checked){
			tot=tot*1+document.getElementById('vadselH'+onumber).value*1;
			res=res+document.getElementById('vadsel'+onumber).value+',';
		}else{
			tot=tot*1-document.getElementById('vadselH'+onumber).value*1;
			res=res.replace(document.getElementById('vadsel'+onumber).value+',','');
		}
			
		document.getElementById('vadval').value=res;
		document.getElementById('vadtot').value=tot;
		document.getElementById('priceTD').innerHTML='$'+tot;
	}
	
	function adcheckFunc2(onumber){
		if(document.getElementById('vadsel'+onumber).checked){
			document.getElementById('vadsel'+onumber).checked=false;
		}
		else{
			document.getElementById('vadsel'+onumber).checked=true;
		}
		adcheckFunc(onumber);
	}
	
	
	function adcheckFunc3(ovalue1,ovalue2){
		var res=document.getElementById('vadval').value;
		var tot=document.getElementById('vadtot').value;
				
		tot=tot*1-ovalue1*1;
		res=res.replace(ovalue2+',','');
		if(tot!=0){
			document.getElementById('SEL_MagazineDIV'+ovalue2).style.display='none';
			var rmDIV=document.getElementById('SEL_MagazineDIV'+ovalue2);
			rmDIV.getElementsByTagName('input')[0].disabled="disabled"; 
			document.getElementById('vadval').value=res;
			document.getElementById('vadtot').value=tot;
			document.getElementById('priceTD').innerHTML='$'+tot;
		}
	}
	

	function flashfullsizeJS(){
	}
	
	
	function fullScreenWin(theURL) {
		
		window.open(theURL, '', 'fullscreen=yes,scrollbars=No,toolbar=No,location=No,directories=No,menubar=No,status=No,titlebar=No,resizable=yes');
	}
	
	function HelpPopUpWin(theURL) {
		
		window.open(theURL, '', 'scrollbars=No,toolbar=No,location=No,directories=No,menubar=No,status=No,titlebar=No,resizable=yes,width=720,height=580');
	}
	
	function PrintpageWin(theURL) {
		
		window.open(theURL, '', 'scrollbars=yes,toolbar=No,location=No,directories=No,menubar=yes,status=No,titlebar=No,resizable=no,width=1000,height=600');
	}
	
	function refreshTabheight(){
		
	}
	
	function pagescriptTAB(tab){
		
		if(document.getElementById(tab.id)){
			
			//setInnerHtmlZap({ html: document.getElementById(tab.id).innerHTML,container: tab.id, inner: false});

			if(tab.id.indexOf('vAdTab_')==-1 || tab.id.indexOf('vAdTabU_')==-1){
				
				refreshTabheight();
				
			}
			
		}
	}
	
	
	var oldremovetab='';
	var oldremovetab2='';
	var oldremovetab3='';
	
	
	
	function ajaxpage(url, containerid)
	{
		
		var page_request = false
		if (window.XMLHttpRequest) 
			page_request = new XMLHttpRequest() 
		else if (window.ActiveXObject) { 
			try { page_request = new ActiveXObject("Msxml2.XMLHTTP") } 
			catch (e){ try{ page_request = new ActiveXObject("Microsoft.XMLHTTP") }
				catch (e){}
			}
		}	
	
		else return false
		page_request.onreadystatechange = function() 
		{
			if(document.getElementById(containerid+'_load'))
			document.getElementById(containerid+'_load').innerHTML = "<table width='16' height='16'><tr><td align='center'><img src='"+vsubpath+"/isimage/spinner.gif' border='0' width='16' height='16'  align=absmiddle></td></tr></table>";
			else
			document.getElementById(containerid).innerHTML = "<table width='16' height='16'><tr><td align='center'><img src='"+vsubpath+"/isimage/spinner.gif' border='0' width='16' height='16' align=absmiddle></td></tr></table>";
			loadpage(page_request, containerid)
		}
		page_request.open('GET', url+"&isajax=true&r="+Math.random(), true)
		page_request.send(null)
	}
	
	function loadpage(page_request, containerid) {
		if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
			//if(document.getElementById(containerid+'_load'))
			//document.getElementById(containerid+'_load').innerHTML="";
			
			document.getElementById(containerid).innerHTML = page_request.responseText;
			removescript(containerid);
			loadscript(containerid);
	}

	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	function ltrim(stringToTrim) {
		return stringToTrim.replace(/^\s+/,"");
	}
	function rtrim(stringToTrim) {
		return stringToTrim.replace(/\s+$/,"");
	}


	function validateEmail(email) {
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   //var address = document.forms[form_id].elements[email].value;
	   var address = document.getElementById(email);
	    var address2 = trim(document.getElementById(email).value);
		
		
	   if(reg.test(address2) == false) {
		  //alert('Invalid Email Address');		  
		  address.className='im_extvalidEmail im_errorValid';
		  return false;
	   }
	   else{
		   address.className='im_extvalidEmail';
		   document.getElementById(email).value=address2;
	   	   return true;
	   }
	}
	
	function validateInputRE(oid,oclass){
		var address = document.getElementById(oid);
		address.className=oclass+' im_errorValid';
	}
	
	function validateEmailImg(email,email2){
		if(validateEmail(email))
			document.getElementById(email2).innerHTML="<img src='"+vsubpath+"/isimage/Tick.png' border=0 width=16 height=16 />"; 
		else 
			document.getElementById(email2).innerHTML="<img src='"+vsubpath+"/isimage/Delete.png' border=0 width=16 height=16 />";	
	}
	
	function validateEmailImg2(email,email2,email1){
		
		if(validateEmail(email1)){
		
			if(document.getElementById(email1).value==document.getElementById(email).value)
				document.getElementById(email2).innerHTML="<img src='"+vsubpath+"/isimage/Tick.png' border=0 width=16 height=16 />"; 
			else
				document.getElementById(email2).innerHTML="<img src='"+vsubpath+"/isimage/Delete.png' border=0 width=16 height=16 />";
		}
		else 
			document.getElementById(email2).innerHTML="<img src='"+vsubpath+"/isimage/Delete.png' border=0 width=16 height=16 />";	
	}
	
	function validateInput(email) {
	   
	   var address = document.getElementById(email);
	   
	   if(address.value=='') {
		  address.className='im_extvalid im_errorValid'; 
		  return false;
	   }
	   else{
		 address.className='im_extvalid'; 
	   	  return true;
	   }
	}

