var standardStyle = '2'; // This is the number of your standard style sheet; this will be used when the user did not do anything.
var nameOfCookie = 'switchstyle'; // This is the name of the cookie that is used.
var TIMER = 5; // Globals for dialog box
var SPEED = 10;
var WRAPPER = 'external-container';

function setOp(op,extra){
		document.opForm.op.value=op;
		document.opForm.extra.value=extra;
		document.opForm.submit();
}

function alertCommentsLength(textareaID,txtCountID){
	var strLength;
	var strMsg;
	if(textareaID == 'topic'){
		var txt_length = 200;
	}
	else{
		var txt_length = 300;
	}

	if($(textareaID).value.length>txt_length){
		strMsg=$(textareaID).value;
		$(textareaID).value=strMsg.substring(0,txt_length);
		$(textareaID).focus();
		return false;
	}
	strLength=$(textareaID).value.length;
	$(txtCountID).value=txt_length-strLength+' characters left';
}
function checkUserCommentsfrm(textareaID,errmsgID){
	var userCommentsVal = $(textareaID).value.replace(/^\s+|\s+$/g, "");
	var ratingValue = $('rating_value').value;
	var suggesionVal = $('SuggestValue').value;
	if(ratingValue == ''){
		$(errmsgID).innerHTML = '<font color="#FF0000" style="font-size: 15px;">Please select rating</font>';
		$(textareaID).focus();
		return false;

	}
	if(userCommentsVal == '' || suggesionVal == ''){		
		$(errmsgID).innerHTML = '<font color="#FF0000" style="font-size: 15px;">Oops ! the \' Shout out \' box seems to be blank !!</font>';
		$(textareaID).focus();
		return false;
	}
	return true;
}

function rollover(val){
	var starSelected = document.getElementById('rating_value').value;
	if(starSelected){
		$('rollover').style.display = 'none';
	}
	else{
		if(val == 1){
			$('rollover').style.display = 'none';
		}
		else if(val == 2){
			$('rollover').style.display = 'block';
		}
	}
}

function showReviewCmtsBx(id){
	$(id).style.display = "block";
}

function saveReviewCmts(ratingID,uid){
	$('Rev_Id').value = ratingID;
	$('Rev_UId').value = uid;
	$('user_rev_cmts').value = $('rev_txtarea_'+ratingID).value;
	if($('user_rev_cmts').value == ''){
		$('reviewCmtsErr').innerHTML = '<font color="#FF0000" style="font-size: 12px;">Please enter comments</font>';
		$('rev_txtarea_'+ratingID).focus();
		return false;
	}
	document.reviewCmtsFrm.submit();
}

function clearTxtArea(){
	var SuggestValue = $('SuggestValue').value;
	if(SuggestValue == ''){
		$('txtcomments').value = "";
		$('SuggestValue').value = 1;
		return false;
	}
}


function optionCmtsFrm(textareaID,errmsgID){
	var userCommentsVal = $(textareaID).value.replace(/^\s+|\s+$/g, "");
	if(userCommentsVal == ''){		
		$(errmsgID).innerHTML = '<font color="#FF0000" style="font-size: 12px;">Please enter comments</font>';
		$(textareaID).focus();
		return false;
	}
	return true;
}

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_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_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 ShwoHide(id){
		//cleanUptxt();
		$('showAll').style.display="block";
	if(id == 1){
		$('videoid').style.display="none";
		$('urlid').style.display="none";
		$('imageid').style.display="block";
		$('upload-img').style.display="block";
		$('upload-video').style.display="none";
		$('upload-url').style.display="none";
		$('or1').style.display="none";
	}else if(id == 0){
		$('videoid').style.display="block";
		$('imageid').style.display="none";
		$('urlid').style.display="none";
		$('upload-img').style.display="block";
		$('upload-video').style.display="block";
		$('upload-url').style.display="none";	
		$('or2').style.display="none";
	}else if(id == 2){
		$('videoid').style.display="none";
		$('imageid').style.display="none";
		$('urlid').style.display="block";
		$('upload-img').style.display="none";
		$('upload-video').style.display="none";
		$('upload-url').style.display="block";	
	}
}

function showAllButtn(){
//		cleanUptxt();
		cleanUptxtNew();
		$('or1').style.display="block";
		$('or2').style.display="block";
		$('videoid').style.display="block";
		$('urlid').style.display="block";
		$('imageid').style.display="block";
		$('upload-img').style.display="none";
		$('upload-video').style.display="none";
		$('upload-url').style.display="none";
		$('showAll').style.display="none";
}


		function Reactit(id){
				$('reatid').value=id;
				switch(id) {
				case "1":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/1.png' style='border:none'/>";	
						$('ShowReact').value = '+LoadingStatus+';
						break;
				case "2":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/2.png' style='border:none'/>";	
						$('ShowReact').value = '<div>'+LoadingStatus+'</div>';
						break;
				case "3":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/3.png' style='border:none'/>";	
						$('ShowReact').value = '<div>'+LoadingStatus+'</div>';
						break;
				case "4":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/4.png' style='border:none'/>";	
						$('ShowReact').value = '<div>'+LoadingStatus+'</div>';
						break;
				case "5":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/5.png' style='border:none'/>";	
						$('ShowReact').value = '<div>'+LoadingStatus+'</div>';
						break;
				case "6":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/6.png' style='border:none'/>";	
						$('ShowReact').value = '<div>'+LoadingStatus+'</div>';
						break;
				case "7":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/7.png' style='border:none'/>";	
						$('ShowReact').value = '<div>'+LoadingStatus+'</div>';
						break;
				case "8":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/8.png' style='border:none'/>";	
						$('ShowReact').value = '<div>'+LoadingStatus+'</div>';
						break;
				case "9":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/9.png' style='border:none'/>";	
						$('ShowReact').value = '<div>'+LoadingStatus+'</div>';
						break;
				default:
					break;
			}

		}

function TReplySubmit(txt){
	document.getElementById('TReply').value = txt;
	var userCommentsVal = $('txtReply').value.replace(/^\s+|\s+$/g, "");
	var userID = $('user_id').value;
	var security_code = $('security_code').value
	if($('reatid').value == ''){
		$('expressionErr').style.display = 'block';
		return false;
	}else if(userCommentsVal == ''){
		$('expressionErr').style.display = 'block';
		$('expressionErr').innerHTML = '<font color="#FF0000" style="font-size: 12px;">Please express something.</font>';
		$('txtReply').focus();
		return false;
	}
	else if(userID == ''){
		if(security_code == ''){
			$('securityTxt').innerHTML = '<font color="#FF0000" style="font-size: 11px;"><br>Please enter the text you see.<br></font>';
			$('security_code').focus();
			return false;
		}
	}else{
		document.treply.submit();
	}
}

function frmValidation(){
	if($('topic').value == ''){
		$('showErrMsg').innerHTML = '<font color="#FF0000" style="font-size: 14px;margin-left:255px;">Please enter topic</font>';
		$('topic').focus();
		return false;
	}
	else if($('tag').value == ''){
		$('showErrMsg').innerHTML = '<font color="#FF0000" style="font-size: 14px;margin-left:255px;">Please enter tag</font>';
		$('tag').focus();
		return false;
	}	
	else if($('rapportCat').value == 'All'){
		$('showErrMsg').innerHTML = '<font color="#FF0000" style="font-size: 14px;margin-left:255px;">Please select category</font>';
		$('rapportCat').className = 'select-box-bold';
		$('rapportCat').focus();
		return false;
	}
	return true;
}

		function ShowReact(id){
				switch(id) {
				case "1":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/1.png' style='border:none'/>";	
						$('ShowReact').innerHTML = '<div>'+LoadingStatus+'</div>';
						break;
				case "2":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/2.png' style='border:none'/>";	
						$('ShowReact').innerHTML = '<div>'+LoadingStatus+'</div>';
						break;
				case "3":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/3.png' style='border:none'/>";	
						$('ShowReact').innerHTML = '<div>'+LoadingStatus+'</div>';
						break;
				case "4":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/4.png' style='border:none'/>";	
						$('ShowReact').innerHTML = '<div>'+LoadingStatus+'</div>';
						break;
				case "5":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/5.png' style='border:none'/>";	
						$('ShowReact').innerHTML = '<div>'+LoadingStatus+'</div>';
						break;
				case "6":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/6.png' style='border:none'/>";	
						$('ShowReact').innerHTML = '<div>'+LoadingStatus+'</div>';
						break;
				case "7":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/7.png' style='border:none'/>";	
						$('ShowReact').innerHTML = '<div>'+LoadingStatus+'</div>';
						break;
				case "8":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/8.png' style='border:none'/>";	
						$('ShowReact').innerHTML = '<div>'+LoadingStatus+'</div>';
						break;
				case "9":
						LoadingStatus="<img src='http://www.areapal.com/rapo/images/9.png' style='border:none'/>";	
						$('ShowReact').innerHTML = '<div>'+LoadingStatus+'</div>';
						break;
				default:
					break;
			}
		}

		function HideReact(id){
				$('ShowReact').innerHTML = '';
//				$('MouseOutClass').style.display = 'block';
				if($('reatid').value == id){
					ImageId= $('reatid').value;
					LoadingStatus='<img src="http://www.areapal.com/rapo/images/' +ImageId+ '.png" style="border:none"/>';
					$('ShowReact').innerHTML = '<div>'+LoadingStatus+'</div>';
					
				}else if($('reatid').value != "") {
					ImageId= $('reatid').value;
					LoadingStatus='<img src="http://www.areapal.com/rapo/images/' +ImageId+ '.png" style="border:none"/>';
					$('ShowReact').innerHTML = '<div>'+LoadingStatus+'</div>';
				}
		}
		
		
		function ShowAnonymous(id){
			if(id == "true"){
				$('HideAnonymous').style.display = 'none';
				$('ShowAnonymous').style.display = 'block';
				$('select').style.display = 'none';
				$('unselect').style.display = 'block';
				
			}else{
				$('HideAnonymous').style.display = 'block';
				$('ShowAnonymous').style.display = 'none';
				$('select').style.display = 'block';
				$('unselect').style.display = 'none';

			}
		}
		
		function showlink(val){
			if(val == 1){
				$('imgLinkDiv').style.display = 'block';
			}else if(val == 2){
				$('videoLinkDiv').style.display = 'block';
			}
		}
		
		function cleanUptxt(){
//			$('imgLink').value = "";
//			$('VideoUrl').value = "";
//			$('videoLinkDiv').value = "";
			//$('LinkUrl').value = "";
			/*var i;
			var imgTotalItem = $('totalitem').value;			
			for(i=0; i<imgTotalItem; i++){
				$('url_'+i).value = '';
			}
			var videoTotalItem = $('vtotalitem').value;			
			for(i=0; i<videoTotalItem; i++){
				$('vurl_'+i).value = '';
			}
			var linkTotalItem = $('linktotalitem').value;			
			for(i=0; i<linkTotalItem; i++){
				$('linkurl_'+i).value = '';
			}*/
			$('totalitem').value = "";
			$('vtotalitem').value = "";
			$('linktotalitem').value = ""; 
		}


		function cleanUptxtNew(){
			$('LinkUrl').value = "";
			$('totalitem').value = "";
			$('vtotalitem').value = "";
			$('linktotalitem').value = ""; 
			$('image').value = "";
			$('VideoUrl').value = "";
			$('totalitem').value = "";
			$('vtotalitem').value = "";
			$('linktotalitem').value = "";
//			$('imgLink').value = "";
//			$('videoLinkDiv').value = "";
			
			/*var i;
			var imgTotalItem = $('totalitem').value;			
			for(i=0; i<imgTotalItem; i++){
				$('url_'+i).value = '';
			}
			var videoTotalItem = $('vtotalitem').value;			
			for(i=0; i<videoTotalItem; i++){
				$('vurl_'+i).value = '';
			}
			var linkTotalItem = $('linktotalitem').value;			
			for(i=0; i<linkTotalItem; i++){
				$('linkurl_'+i).value = '';
			}*/			
		}

//---------------------------------------------------------------------------------------------------------------------------
// Dialog Box functions
//---------------------------------------------------------------------------------------------------------------------------
// calculate the current window width //
function pageWidth() {
  return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

// calculate the current window height //
function pageHeight() {
  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

// calculate the current window vertical offset //
function topPosition() {
  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

// calculate the position starting at the left of the window //
function leftPosition() {
  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

// build/show the dialog box, populate the data and call the fadeDialog function //
function openPopUpHome() {
	var standardStyle = '2'; // This is the number of your standard style sheet; this will be used when the user did not do anything.
	var nameOfCookie = 'switchstyle'; // This is the name of the cookie that is used.
	var TIMER = 5; // Globals for dialog box
	var SPEED = 10;
	var WRAPPER = 'external-container';

  var dialog;
  var dialogcontent;
  var dialogmask;
  if(!$('dialogBox')) {
    dialog = document.createElement('div');
    dialog.id = 'dialogBox';
    dialogcontent = document.createElement('div');
    dialogcontent.id = 'dialog-content';
    dialogmask = document.createElement('div');
    dialogmask.id = 'dialog-mask';
    document.body.appendChild(dialogmask);
    document.body.appendChild(dialog);
    dialog.appendChild(dialogcontent);;
    dialogmask.setAttribute('onclick','hideDialog()');
    dialogmask.onclick = hideDialog;
  } else {
    dialog = $('dialogBox');
    dialogcontent = $('dialog-content');
    dialogmask = $('dialog-mask');
    dialogmask.style.visibility = "visible";
    dialog.style.visibility = "visible";
  }
  dialog.style.opacity = .00;
  dialog.style.filter = 'alpha(opacity=0)';
  dialog.alpha = 0;
  var width = pageWidth();
  var height = pageHeight();
  var left = leftPosition();
  var top = topPosition();
  var dialogwidth = dialog.offsetWidth;
  var dialogheight = dialog.offsetHeight;
  var topposition = top + (height / 2) - (dialogheight / 2);
  var leftposition = left + (width / 2) - (dialogwidth / 2);
//  dialog.style.top = topposition + "px";
  dialog.style.top = "27px";//added by rajaraman
  dialog.style.left = leftposition + "px";
  dialogcontent.className = 'dialogcontent';
  var content = $(WRAPPER);
  dialogmask.style.height = content.offsetHeight + 'px';
  dialog.timer = setInterval("fadeDialog(1)", TIMER);
  popUpAjax() // call Ajax dunction to laod
  return false;
}

function popUpAjax(){
	new Ajax.Request('popUpAjax.php?key=up', {
		onLoading:function(transport) {
			$('dialog-content').innerHTML=$('loadingAjaxContent').innerHTML;
		},					 
		onSuccess: function(transport) {
			$('dialog-content').innerHTML=transport.responseText;
		}
	});
}


function repositionDialog() {
    dialog = $('dialogBox');
	var width = pageWidth();
	var left = leftPosition();
	var dialogwidth = dialog.offsetWidth;
	var leftposition = left + (width / 2) - (dialogwidth / 2);
	dialog.style.left = leftposition + "px";
}

// hide the dialog box //
function hideDialog() {
  var dialog = $('dialogBox');
  clearInterval(dialog.timer);
  dialog.timer = setInterval("fadeDialog(0)", TIMER);
}

// fade-in the dialog box //
function fadeDialog(flag) {
  if(flag == null) {
    flag = 1;
  }
  var dialog = $('dialogBox');
  var value;
  if(flag == 1) {
    value = dialog.alpha + SPEED;
  } else {
    value = dialog.alpha - SPEED;
  }
  dialog.alpha = value;
  dialog.style.opacity = (value / 100);
  dialog.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(dialog.timer);
    dialog.timer = null;
    document.body.setAttribute('onResize','repositionDialog()');
	document.body.onResize = "repositionDialog";
} else if(value <= 1) {
    dialog.style.visibility = "hidden";
    $('dialog-mask').style.visibility = "hidden";
    clearInterval(dialog.timer);
	window.onResize = "";
  }
}


function imgShwoHide(id){
	if(id == 1){
		$('upload-img').style.display="block";
	}
}

var k = 0;
function generate(){//this is for image link
	$('imgLinkDiv').style.display = 'block';
	mynewrow=document.getElementById('tblid').insertRow(-1);
	mynewrow.id=k;
	fcell=mynewrow.insertCell(-1);	
	fcell.innerHTML='<span class="HintText">URL : </span><input type="text" id="url_'+k+'" name="url_'+k+'" value="" class="txtbx" size="35"><span class="HintText" style="padding-left:30px; clear:left; float:left;">( http://www.test.com )';
	k+=1;
	document.getElementById('totalitem').value=k;
}
function generateVideoUrl(){//this is for video link
	$('videoLinkDiv').style.display = 'block';
	mynewrow=document.getElementById('videotblid').insertRow(-1);
	mynewrow.id=k;
	fcell=mynewrow.insertCell(-1);	
	fcell.innerHTML='<span class="HintText">URL : </span><input type="text" id="vurl_'+k+'" name="vurl_'+k+'" value="" class="txtbx" size="35"><span class="HintText" style="padding-left:30px; clear:left; float:left;">( http://www.test.com )';
	k+=1;
	document.getElementById('vtotalitem').value=k;
}

function generateLinkUrl(){//this is for video link
	$('linkLinkDiv').style.display = 'block';
	mynewrow=document.getElementById('linktblid').insertRow(-1);
	mynewrow.id=k;
	fcell=mynewrow.insertCell(-1);	
	fcell.innerHTML='<span class="HintText">URL : </span><input type="text" id="linkurl_'+k+'" name="linkurl_'+k+'" value="" class="txtbx" size="35"><span class="HintText" style="padding-left:30px; clear:left; float:left;">( http://www.test.com )';
	k+=1;
	document.getElementById('linktotalitem').value=k;
}



function showAllBtn(){//for cmts page
		$('upload-img').style.display="none";
/*		$('or1').style.display="block";
		$('or2').style.display="block";
		$('videoid').style.display="block";
		$('urlid').style.display="block";
		$('imageid').style.display="block";
		
		$('upload-video').style.display="none";
		$('upload-url').style.display="none";
		$('showAll').style.display="none";
*/}



function loadCity(key) {
	new Ajax.Request('rapoajax.php?af=loadCity&key='+key, {
		 onSuccess: function(transport) { 
		 	 var respose = transport.responseText;
			 $('cityHide').style.display = 'block';
			 $('cityDropDown').innerHTML=respose;
//			 loadArea($('select_city').value);
		 } 	 
	}); 
}

function loadArea(key) {
	new Ajax.Request('rapoajax.php?af=loadArea&key='+key, {
		 onSuccess: function(transport) { 
		 	 var respose = transport.responseText;
			 $('areaDropDown').innerHTML=respose;
		 } 
	}); 
}

function loadState(key) {
	new Ajax.Request('rapoajax.php?af=loadState&key='+key, {
		 onSuccess: function(transport) { 
		 	 var respose = transport.responseText;				
			$('stateHide').style.display = 'block';
			$('stateDropDown').innerHTML=respose;
//			 loadCity($('select_state').value);
		 } 	 
	}); 
}

function showRegion(){
	$('regionContainer').style.display = 'block';
	$('addRegion').value = 1;
}


function OpenAdwindow(){
window.open("downloadmoviepopup.html",'welcome','width=345,height=290,toolbar=no,status=no,location=no,menubar=no,directories=no,scrollbars=no,resizable=no');
}
