/*
	Copyright Infinite Solutions Co.,Ltd 2010;
	mediaweb.js v 2.0 2010.04.01;
	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++;
			}	
			
			selectInd=0;
			while(Checkform.getElementsByTagName('select')[selectInd])
			{			
				var testselect=Checkform.getElementsByTagName('select')[selectInd];						
				//toconvert('wintoutf',testarea);	
				
				if (testselect.className.indexOf("im_extvalid")!=-1 ) {
					if(!validateInput(testselect.id)){
						formError++;						
					}
				}
				
				selectInd++;
			}	
		}
		//alert(formError);
		if(formError==0)
			return true;
		else	
			return false;
	}
	
	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)
	{
		if(vsubpath2=='')
			path='/';
		else
			path=vsubpath2;
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+
		";path="+path;
	}
	
	var oldsel=[];	
	var lenchcolor1=[];
	var lenchcolor2=[];
	var lenchcolor3=[];
	
	lenchcolor1['mmenumain2_']='mmenu_itemon2';
	lenchcolor2['mmenumain2_']='mmenu_itemoff2';
	lenchcolor3['mmenumain2_']='mmenu_itemon2';
	oldsel['mmenumain2_']=getCookie('mmenumain2_');
	oldsel['mmenumain2_id']='MenuMainMedia2';
	

	lenchcolor1['mmenumain3_']='mmenu_itemon3';
	lenchcolor2['mmenumain3_']='mmenu_itemoff3';
	lenchcolor3['mmenumain3_']='mmenu_itemon3';
	oldsel['mmenumain3_']=getCookie('mmenumain3_');
	oldsel['mmenumain3_id']='MenuMainMedia3';
	
	function reqLenFunc(otype,oele,oid,ocode){
		
		if(!oele.id){
			oele=document.getElementById(oele);
		}
		
		var jsTRid;
		jsTRid=ocode+oldsel[ocode];
		fspea=oid*1;
		nspea=oid*1+1;
		
		cur_fspea=oldsel[ocode]*1;
		cur_nspea=oldsel[ocode]*1+1;
		
		
		if(otype=='over' && oele.id!=jsTRid){			
			oele.className=lenchcolor1[ocode];
			
			if(document.getElementById(ocode+'spea_'+fspea)){
				document.getElementById(ocode+'spea_'+fspea).className=ocode+'spea0_sel';
			}
			if(document.getElementById(ocode+'spea_'+nspea)){
				document.getElementById(ocode+'spea_'+nspea).className=ocode+'spea0_sel';
			}
		}
		
		if(otype=='out' && oele.id!=jsTRid){
			oele.className=lenchcolor2[ocode];
			if(document.getElementById(ocode+'spea_'+fspea) &&  cur_fspea!=fspea && cur_nspea!=fspea){
				document.getElementById(ocode+'spea_'+fspea).className=ocode+'spea0';
			}
			if(document.getElementById(ocode+'spea_'+nspea) &&  cur_nspea!=nspea && cur_fspea!=nspea){
				document.getElementById(ocode+'spea_'+nspea).className=ocode+'spea0';
			}
			
		}
		
		if(otype=='click'){
			
			if(oldsel[ocode]!=0){
				
				if(document.getElementById(jsTRid)){
					document.getElementById(jsTRid).className=lenchcolor2[ocode];
				}
				if(document.getElementById('body_'+jsTRid)){
					document.getElementById('body_'+jsTRid).style.display='none';
				}
			}
			
			if(document.getElementById(ocode+'spea_'+fspea)){
				document.getElementById(ocode+'spea_'+fspea).className=ocode+'spea0_sel';
			}
			if(document.getElementById(ocode+'spea_'+nspea)){
				document.getElementById(ocode+'spea_'+nspea).className=ocode+'spea0_sel';
			}
			
	
			oldsel[ocode]=oid;

			
			setCookie(ocode,oid,1);
			setCookie(ocode,oid,1);
			
			
			
			oele.className=lenchcolor3[ocode];
			if(document.getElementById('body_'+oele.id)){
				document.getElementById('body_'+oele.id).style.display='block';
			}

		}
		
	}
	
	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 = 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';	
	   	   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+"/img/Tick.png' border=0 width=16 height=16 />"; 
		else 
			document.getElementById(email2).innerHTML="<img src='"+vsubpath+"/img/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+"/img/Tick.png' border=0 width=16 height=16 />"; 
			else
				document.getElementById(email2).innerHTML="<img src='"+vsubpath+"/img/Delete.png' border=0 width=16 height=16 />";
		}
		else 
			document.getElementById(email2).innerHTML="<img src='"+vsubpath+"/img/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;
	   }
	}
	
	var mask;
	 var maskForm;
	 var hisadd;
	 hischange=true;
	 
	function simplepage(ourl,omethod,oelement,osend,obusyelement,ohistory,ofunc){

		var strAS={};
		var osendf;
		var newurl;
		if(osend)
			osendf=osend;
		else
			osendf='';
		if(osend!='' || ourl.indexOf("?")!= -1){
			
			if(ourl.indexOf("?")!= -1){
				
				if(osendf!='')
					osendf=ourl.split('?')[1]+'&'+osend;
				else
					osendf=ourl.split('?')[1];
				ourl=ourl.split('?')[0];
			}
			
			var strASjs={};
			if(osendf.indexOf("&")!= -1)
				strASjs=osendf.split('&');
			else
				strASjs[0]=osendf;
			strSeind=0;
			
			while(strASjs[strSeind]){
				if(strASjs[strSeind].indexOf("=")!= -1){
					strAS[strASjs[strSeind].split('=')[0]]=strASjs[strSeind].split('=')[1];
				}
				strSeind=strSeind+1;
			}
		}
		
		
		oloadcallback=function(){
			
			//mask.hide();
		
			if(typeof(ofunc)=="function")				
									ofunc(); 
		};
		
		strAS['isajax']='true';
		var tabup=Ext.get(oelement).getUpdater();
		tabup.update({
			url: ourl,
			method: omethod,
			//scope: this,	
			waitMsg: 'Loding ...',
			params: strAS,
			scripts:true,
			callback:oloadcallback
			//async: false
		});
		
	}
	
	function ajaxpage(ourl,oelement){
			simplepage(ourl,'GET',oelement,'',oelement,'false');
	}

	
	
	/******* 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-800)/2;
		newPosY=winH-600;
		if(document.getElementById('ep-comp-MSG1002')){
			
			if(document.getElementById('ep-genMSG57') && otit!=''){
				document.getElementById('ep-genMSG57').innerHTML=otit;
			}
			if(document.getElementById('ep-genMSG68') && otext!=''){
				document.getElementById('ep-genMSG68').innerHTML=otext;
			}
			if(document.getElementById('ep-genMSG56')){
				document.getElementById('ep-genMSG56').setAttribute("width",winW);
				document.getElementById('ep-genMSG56').setAttribute("height",winH);	
				document.getElementById('ep-genMSG56').style.display='block';
			}
			
			if(document.getElementById('ep-comp-MSG1002')){
			document.getElementById('ep-comp-MSG1002').style.top=newPosY+'px';
			document.getElementById('ep-comp-MSG1002').style.left=newPosX+'px';
			document.getElementById('ep-comp-MSG1002').style.visibility='visible';
			}
			
		}
		

	}
	
	function alertclose(){
		if(document.getElementById('ep-comp-MSG1002')){			
			document.getElementById('ep-comp-MSG1002').style.top='-1000px';
			document.getElementById('ep-comp-MSG1002').style.left='-1000px';
			document.getElementById('ep-comp-MSG1002').style.visibility='hidden';
			document.getElementById('ep-genMSG56').style.display='none';
		}	
		
	}
	
	
	function alertchange(otype){
		
		if(otype=='alert'){
			if(document.getElementById('ep-genMSGOK21')){		
				document.getElementById('ep-genMSGOK21').className='x-panel-btn-td';
				document.getElementById('ep-genMSGCANCEL45').className='x-panel-btn-td x-hide-offsets';
				document.getElementById('ep-genMSGlogo').className='ext-mb-fix-cursor';
			}	
		}
		else
			if(otype=='window'){
				if(document.getElementById('ep-genMSGOK21')){		
					document.getElementById('ep-genMSGOK21').className='x-panel-btn-td x-hide-offsets';
					document.getElementById('ep-genMSGCANCEL45').className='x-panel-btn-td';
					document.getElementById('ep-genMSGlogo').className='';
				}
			}
			else
				if(otype=='form'){
					if(document.getElementById('ep-genMSGOK21')){		
						document.getElementById('ep-genMSGOK21').className='x-panel-btn-td x-hide-offsets';
						document.getElementById('ep-genMSGCANCEL45').className='x-panel-btn-td x-hide-offsets';
						document.getElementById('ep-genMSGlogo').className='';
					}
				}
	}


	/******* Alert MSG END ***********/	
	
	
	function moveform(oformId,toformId)
	{
	
		var fromform=document.getElementById(oformId);
		var toForm=document.getElementById(toformId);
		if(fromform && toForm)
		{
			inputInd=0;	
			while(fromform.getElementsByTagName('input')[inputInd])
			{
				var chel=fromform.getElementsByTagName('input')[inputInd];		
				if(chel.type=='text' || chel.type=='hidden'){	
					
					var newinput = document.createElement('input');				
					newinput.setAttribute('id',chel.id);
					newinput.setAttribute('name',chel.name);
					newinput.setAttribute('type',"hidden");
					newinput.value = chel.value;
					toForm.appendChild(newinput);
				}
				inputInd++;
			}
			textareaInd=0;
			while(fromform.getElementsByTagName('textarea')[textareaInd])
			{		
				var chel=fromform.getElementsByTagName('textarea')[textareaInd];	
				var newinput = document.createElement('input');				
				newinput.setAttribute('id',chel.id);
				newinput.setAttribute('name',chel.name);
				newinput.setAttribute('type',"hidden");
				newinput.value = chel.value;
				toForm.appendChild(newinput);
				textareaInd++;
			}
			selectInd=0;
			while(fromform.getElementsByTagName('select')[selectInd])
			{		
				var chel=fromform.getElementsByTagName('select')[selectInd];	
				var newinput = document.createElement('input');				
				newinput.setAttribute('id',chel.id);
				newinput.setAttribute('name',chel.name);
				newinput.setAttribute('type',"hidden");
				newinput.value = chel.value;
				toForm.appendChild(newinput);
				selectInd++;
			}
		}
		
	}
	
	
	oldid=0;
	function experthome(oid)
	{
		
		if(document.getElementById('divExpert'+oid).style.display=='none')	
			document.getElementById('divExpert'+oid).style.display='inline';
		else
			document.getElementById('divExpert'+oid).style.display='none';
	
		if(oldid!=0 && oldid!=oid)
			document.getElementById('divExpert'+oldid).style.display='none';
		
		document.getElementById('divExpert'+oid).style.display='inline';
		oldid=oid;
	}
	
	
	oldidR=0;
	function experthome2(oid)
	{
		
		if(document.getElementById('divExpertR'+oid).style.display=='none')	
			document.getElementById('divExpertR'+oid).style.display='inline';
		else
			document.getElementById('divExpertR'+oid).style.display='none';
	
		if(oldidR!=0 && oldidR!=oid)
			document.getElementById('divExpertR'+oldidR).style.display='none';
		
		document.getElementById('divExpertR'+oid).style.display='inline';
		oldidR=oid;
	}
	
	function form_post(formid,element,val){
		
		if(document.getElementById(formid) && document.getElementById(element)){
			document.getElementById(element).value=val;
			
			document.getElementById(formid).submit();
			
		}
	}
	
	function form_post_tender(formid,element,val){
		
		if(document.getElementById(formid) && document.getElementById(element)){
			document.getElementById(element).value=val;
			document.getElementById('ta').value='1';
			document.getElementById(formid).submit();
			
		}
	}
	
	function form_postBlank(formid,element,val,path,target){
		
		if(document.getElementById(formid) && document.getElementById(element)){
			document.getElementById(element).value=val;
			var oldTarget=document.getElementById(formid).target;
			var oldAction=document.getElementById(formid).action;
			document.getElementById(formid).target=target;
			document.getElementById(formid).action=path;
			document.getElementById(formid).submit();
			document.getElementById(formid).target=oldTarget;
			document.getElementById(formid).action=oldAction;
			document.getElementById(element).value="";
		}
	}
	
	function ep_blockNone(value,elS,elE){
		if(value=='yes'){
			document.getElementById(elS).style.display='none';
			document.getElementById(elE).style.display='block';
		}
		else{
			document.getElementById(elS).style.display='block';
			document.getElementById(elE).style.display='none';
		}		
	}
