var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/

function CreateBookmarkLink() {
	title = "Pimp.co.il - סרסר את הסרטונים שלך!";
	url = "http://www.pimp.co.il";
	if (document.all) {
		window.external.AddFavorite( url, title);
	} else {
		alert("Press Ctrl+D");
		//if (window.sidebar) {
		//window.sidebar.addPanel(title, url,"");
		//} else
		//window.external.AddFavorite( url, title); }
		//else if(window.opera && window.print) {
		//			return true; }
	}
}

/* Cookies Function */
function CinArray(id) {
	var Cookie=getCookie('votestring');
	if (Cookie) {
		var mytool_array=Cookie.split(",");
		for (var i in mytool_array) {
			if (mytool_array[i]==id) {
				return true;
			}
		}
	}
	return false;
}


function _site_createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}


function AddVCookie(id) {
	var Cookie=getCookie('votestring');
	if (Cookie) {
		var mytool_array=Cookie.split(",");
		for (var i in mytool_array) {
			if (mytool_array[i]==id) {
				return;
			}
		}
		if (id)
		_site_createCookie("votestring",Cookie+","+id,1);
	} else {
		_site_createCookie("votestring",","+id,1);
	}
}


/* Cookies Function */


if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	try {
		xmlhttp = new XMLHttpRequest ();
	} catch (e) {
		xmlhttp = false}
}

function myXMLHttpRequest () {
	var xmlhttplocal;
	try {
		xmlhttplocal = new ActiveXObject ("Msxml2.XMLHTTP")}
		catch (e) {
			try {
				xmlhttplocal = new ActiveXObject ("Microsoft.XMLHTTP")}
				catch (E) {
					xmlhttplocal = false;
				}
		}

		if (!xmlhttplocal && typeof XMLHttpRequest != 'undefined') {
			try {
				var xmlhttplocal = new XMLHttpRequest ();
			}
			catch (e) {
				var xmlhttplocal = false;
				alert ('couldn\'t create xmlhttp object');
			}
		}
		return (xmlhttplocal);
}

var mnmxmlhttp = Array ();
var mnmString = Array ();
var mnmPrevColor = Array ();
var responsestring = Array ();
var myxmlhttp = Array ();
var responseString = new String;

function wanksit(id,md5) {
	if (xmlhttp && id) {
		url = "/index.php?name=voteXML";
		content = "id=" + id + "&votev=" + md5;
		mnmxmlhttp[id] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
			mnmxmlhttp[id].open ("POST", url, true);
			mnmxmlhttp[id].setRequestHeader ('Content-Type',
			'application/x-www-form-urlencoded');
			mnmxmlhttp[id].send (content);

			mnmxmlhttp[id].onreadystatechange = function () {
				if (mnmxmlhttp[id].readyState == 4) {
					mnmString[id] = mnmxmlhttp[id].responseText;
					changemnmvalues(id, false);
				}
			}
		}
	}
}


function changemnmvalues (id, error) {	
	split = new RegExp ("~--~");
	b = mnmString[id].split (split);
	makeHTstr(id,b[2],b[0],b[1]);
	return false;
}

function voteImg(Nvote,Newsid) {
	AddVCookie(Newsid,'News');
	wanksit(Newsid,Nvote);
}

var Str = new Image ();
Str.src ="/media/starorange.jpg";
var UnStr = new Image ();
UnStr.src ="/media/starblue.jpg";

var AvrgImg,PicturID;
function changeStr(StrNum) {
	var Obj,i;
	if (StrNum>0) {
		for (i=StrNum;i<=5;i++) {
			Obj=document.getElementById('IMG'+i);
			Obj.src=UnStr.src;
		}
		for (i=1;i<=StrNum;i++) {
			Obj=document.getElementById('IMG'+i);
			Obj.src=Str.src;
		}
	} else {
		for (i=1;i<=5;i++) {
			Obj=document.getElementById('IMG'+i);
			if (AvrgImg>=i) {
				Obj.src=Str.src;
			} else {
				Obj.src=UnStr.src;
			}
		}
	}
}

function makeHTstr(Newsid,StrNum,NumVotINT,SumAvrgFloat) {
	AvrgImg=StrNum;
	PicturID=Newsid;
	var NumVObj=document.getElementById('NumVot');
	if (NumVObj) NumVObj.innerHTML=NumVotINT;
	var SumAvrg=document.getElementById('sumVote');
	if (SumAvrg) SumAvrg.innerHTML=SumAvrgFloat;
	var i;
	IgnoreVote=(CinArray(Newsid,'News'))?true:false;
	var oDivRes = document.getElementById('PasteDiv');
	oDivRes.innerHTML='<table cellpadding="0" cellspacing="0" border="0" dir="rtl"><tr>';
	if (!IgnoreVote) {
		for (i=1;i<=5;i++) {
			oDivRes.innerHTML+='<td><img id="IMG'+i+'" alt="*" onclick="voteImg('+i+',PicturID)" onmouseover="javascript:changeStr('+i+')" src="/media/starblue.jpg"></td>';
		}
	} else {
		for (i=1;i<=5;i++) {
			oDivRes.innerHTML+='<td><img id="IMG'+i+'" alt="*" src="/media/starblue.jpg"></td>';
		}
	}
	oDivRes.innerHTML+='</tr></table>';
	changeStr(0);
}



function AddSmile(Val) {
	var Obj=document.getElementById('content');
	Obj.value+=" "+Val+" ";
}


function onkeyup_shot(oobjc) { oobjc.style.border='1px solid black'; }

function verfy_form(id) {
	var FocusFlag=0; var Error_string='';
	var oobJ=document.getElementById('username');
	if (oobJ) { if (!oobJ.value.length) {
		Error_string+='חובה להזין שם משתמש.\n';
		if (!FocusFlag) { FocusFlag=true; oobJ.focus();}
	}
	}
	var oobJ=document.getElementById('content');
	if (oobJ) { if (!oobJ.value.length) {
		Error_string+='חובה לרשום תוכן בתגובה.\n';
		if (!FocusFlag) { FocusFlag=true; oobJ.focus();}
	}
	}
	if (Error_string.length) {
		alert(Error_string); return false;
	}
		
	var content="send=1&";
	ValAr=new Array('username','content','isuser');
	for (i=0;i<=(ValAr.length-1);i++) {
		obJone=document.getElementById(ValAr[i]);
		content+=ValAr[i]+"="+obJone.value+"&";
	}

	if (xmlhttp && id) {
		
		url = "/index.php?name=player&action=iframe&id="+id;
		mnmxmlhttp[id] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
			var ObjFav=document.getElementById('FormCon');
			if (ObjFav) {
				ObjFav.innerHTML='נא להמתין...';
				ObjFav.style.color='red';
			}
			mnmxmlhttp[id].open ("POST", url, true);
			mnmxmlhttp[id].setRequestHeader ('Content-Type',
			'application/x-www-form-urlencoded');
			mnmxmlhttp[id].send (content);
			mnmxmlhttp[id].onreadystatechange = function () {
				if (mnmxmlhttp[id].readyState == 4) {
					ObjFav.innerHTML='תגובה נקלטה ונשלחה לאישור.';
				}
			}
		}
	}
}
function ChangeFavor(id) {
	if (xmlhttp) {
		url = "/index.php?name=voteXML&file=addfav";
		content = "id=" + id;
		mnmxmlhttp[id] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
			var ObjFav=document.getElementById('favo');
			if (ObjFav) ObjFav.innerHTML='אנא המתן...';
			mnmxmlhttp[id].open ("POST", url, true);
			mnmxmlhttp[id].setRequestHeader ('Content-Type',
			'application/x-www-form-urlencoded');
			mnmxmlhttp[id].send (content);
			errormatch = new RegExp ("^ERROR:");
			mnmxmlhttp[id].onreadystatechange = function () {
				if (mnmxmlhttp[id].readyState == 4) {
					mnmString[id] = mnmxmlhttp[id].responseText;
					if (mnmString[id].match (errormatch)) {
						mnmString[id] = mnmString[id].substring (6, mnmString[id].length);
						alert (mnmString[id]);
						changemnmvalues (id, true);
					} else {
						if (ObjFav) ObjFav.innerHTML=mnmString[id];
					}
				}
			}
		}
	}
}

function report_problem(id) {
	if (confirm("האם ברצונך לדווח על סרטון זה כסרטון לא ראוי ?")) {

		if (xmlhttp) {
			url = "/index.php?name=voteXML&file=break";
			mnmxmlhttp[id] = new myXMLHttpRequest ();
			if (mnmxmlhttp) {
				var ObjFav=document.getElementById('Break');
				if (ObjFav) ObjFav.innerHTML='הדיווח התקבל';
				mnmxmlhttp[id].open ("POST", url, true);
				mnmxmlhttp[id].setRequestHeader ('Content-Type',
				'application/x-www-form-urlencoded');
				mnmxmlhttp[id].send (content);
			}
		}
	}
}

function sendfriend(SID) {
	document.getElementById('SendFriend').style.display='block';
	document.getElementById('SendFriend').src='/index.php?name=users&file=sendfriend&id='+SID;
}

